hud*_*dds 3 php mysql loops while-loop
我只是想从我的数据库中显示一个基本列表或项目,但由于某种原因它没有显示第一个项目,所以如果一个类别中只有一个东西它没有显示任何东西但是如果有2它将显示一个项目.我已添加以下代码.
询问
//this query will fetch 4 records only!
$latestVideos = mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 5")or die(mysql_error());
$posts = mysql_fetch_array($latestVideos);
Run Code Online (Sandbox Code Playgroud)
循环
while($posts = mysql_fetch_array($latestVideos)){
$dateFormat= $posts['video_date'];
$newDate=date('d-m-Y',strtotime($dateFormat));
echo $posts['video_title']
echo $newDate;
echo $posts['video_embed'];
}
Run Code Online (Sandbox Code Playgroud)
mysql_fetch_array 用于在while循环的每次迭代中返回数组的一行.
extra mysql_fetch_array将第一行放入post,并在while循环的第一次迭代中将第二行放入post.
这就是你应该做的.
$latestVideos = mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 5")or die(mysql_error());
while($posts = mysql_fetch_array($latestVideos)){
//do stuff here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5487 次 |
| 最近记录: |