[英]How can I SELECT a single result from a mySQL database
I need to fetch data that is owned by each user.我需要获取每个用户拥有的数据。 DB saves it with current user name and their data.
DB 用当前用户名和他们的数据保存它。 Each user has many data rows.
每个用户有许多数据行。 I need to get each users one row to be displayed every hour?
我需要让每个用户每小时显示一行吗? so every one hour each users row1 changes to each users row2, when the rows finished it has to be loop again.
所以每隔一小时,每个用户的 row1 都会更改为每个用户的 row2,当行完成时,它必须再次循环。
DB fields: id, name, message数据库字段:id、名称、消息
$select=mysql_query("select * from commenttable where name='?'");
while($row=mysql_fetch_array($select))
echo "<div id='sty'>";
echo "<img src='files/fav icon.png'"."' width='50px' height='50px' align='left' />";
echo "<div id='nameid'>".$row['name']."</div>";
echo "<div id='msgid'>".$row['message']."</div>";
echo "</div><br />";
You are missing '{'你缺少“{”
while($row=mysql_fetch_array($select))
{
echo "<div id='sty'>";
echo "<img src='files/fav icon.png'"."' width='50px' height='50px' align='left' />";
echo "<div id='nameid'>".$row['name']."</div>";
echo "<div id='msgid'>".$row['message']."</div>";
echo "</div><br />";
}
May be PHP Cookie will help you in getting records as :- Your table must have a column creationDate可能是 PHP Cookie 将帮助您获取记录:- 您的表必须有一个列 creationDate
<?php
if(!isset($_COOKIE['lastRecord']))
$select=mysql_query("select * from commenttable where name='?' order by creationDate DESC limit 1");
else{
$lastRecord=$_COOKIE['lastRecord'];
$select=mysql_query("select * from commenttable where name='?' and creationDate < '{$lastRecord}'order by creationDate DESC limit 1");
unset($_COOKIE['lastRecord']);
}
while($row=mysql_fetch_array($select)){
echo "<div id='sty'>";
echo "<img src='files/fav icon.png'"."' width='50px' height='50px' align='left' />";
echo "<div id='nameid'>".$row['name']."</div>";
echo "<div id='msgid'>".$row['message']."</div>";
echo "</div><br />";
setcookie('lastRecord',$row['creationDate'],time() + (86400 * 30));
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.