【发布时间】:2011-09-02 20:43:51
【问题描述】:
很抱歉问了两次,但另一个已关闭,因为它缺少重要信息,我很抱歉,但是我的代码是这样的:
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?
【问题讨论】:
-
url 的 ref 部分不是迭代它只是去 0
-
用这个代替
preg_replace():if ( ! ctype_digit($_GET['id'])) die('Invalid input'); else $id = (int) $_GET['id']; -
...您将 $i 设置为 -1,然后将其递增一次 - 在这种情况下它将始终为 0,是的。
-
webbiedave,它显示在我的,但代码是: if($type == "video"){ $i++; $videos .='
- '.$title.'
'; } 对于所有出现的条目,它显示 ref=0 它只添加到 $i 一次 -
$i=-1;
标签: php while-loop iteration