简体   繁体   English

如何从 mySQL 数据库中选择单个结果

[英]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.

相关问题 如何使用php从mysql数据库中选择相似的记录? - How can I select similar records from mysql database with php? 如何在浏览器上打印选择查询结果? 不显示从数据库获取的结果 - how can I print Select query result on the browser? Not displaying the result fetch from the database 如果我有几行具有相同的值,如何从mysql结果中获取单个值 - How can I get a single value from a mysql result, if I have several rows with the same value 如何在MySQL数据库中添加单个用户的多个地址 - How can I add multiple addresses of single user in MySQL database 如何避免mysql_result上来自mySQL的错误? - How can I avoid the error from mySQL on mysql_result? 我怎样才能单独在MySQL数据库的表中选择一行在php的anthor页面中? - how can i select one row from table in MySQL database alone in anthor page with php? 如何从下拉选择框列表中将用户选择的选项的值存储到mysql数据库中? - How can I store the value of a user selected option from a drop down select box list into mysql database? 如何从mySQL数据库中选择数据并以良好的形式编写代码? - How can I select data from mySQL database and write the code in a good form? 如何在mysql数据库的特定列中选择最后一个值? - How can i select the last value in a particular column in mysql database? 如何从PHP中的MySQL数据库中选择一个随机行? - How can to select a random row from a MySQL database in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM