[英]iteration within a while loop
很抱歉要問兩次,但是另一個因為缺少重要信息而被關閉了,我道歉但是我的代碼是這樣的:
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "connect.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
// Use this var to check to see if this ID exists, if yes then get the bio info
$sql = mysql_query("SELECT * FROM bio\n"
. "LEFT JOIN bio_media \n"
. "ON bio.id=bio_media.bioid\n"
. "WHERE bio.id = ".$id."\n"
. "\n"
. " LIMIT 0, 30 ");
// get all the bio details
while($row = mysql_fetch_array($sql)){
$name = $row["name"];
$age = $row["age"];
$division = $row["division"];
$pic = $row["pic"];
$story = $row["story"];
$fb = $row["fb"];
$tw = $row["tw"];
$type = $row['type'];
$file = $row['file'];
$alt = $row['alt'];
$title = $row['title'];
$Age= DetermineAgeFromDOB ($age);
while ($type == "image"){
$images .='<a rel="lb[pp_gal]" href="images/'.$file.'" ><img width="60px" alt="'.$alt.'" title="'.$title.'" src="images/'.$file.'" /></a>';
break;
}
$i=-1;
if($type == "video"){
$i++;
$videos .='<li><a href="watch.php?id='.$id.'&v='.$file.'&ref='.$i.'?iframe=true&width=745&height=520" rel="lb" title="'.$alt.'">'.$title.'</a></li>';
}
問題:如何獲取URL的“ref”部分以更新數據庫中每個條目的+1?
如果我理解正確,你必須擺脫$i=-1;
在循環中只是把$i=0;
在循環之前。
順便說一句,你每次都在覆蓋循環中的變量; 或者只是將$row
添加到數組並使用它或者根本不使用這些臨時變量,只需在需要的地方直接使用$row
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.