我想获取多行输出,我知道使用 while 循环可以轻松完成,但我的问题是,如果我使用 while 循环,相应行的标题就会出现。我只是不想改标题,而是想改内容。这是我想要的简单数据
tableA
id title msg
1 eeee frrffrfrrfrr
2 vvfdfd ffvfvdfvddd
3 vffdcadvg fdfvddfgvre
4 dfdf fvvvf
因此,如果我使用 while 循环,那么该行的标题也会出现,所以我只想继续更改行['message'] 值。我的简单 MySQL 查询是
$res = mysql_query("select * from tableA");
$row = mysql_fetch_array($res);
$msg=$row['msg']
如您所见,它可以轻松显示相应行的标题和消息,但我想要一行的标题和 4 行的消息输出,如何完成?
最佳答案
使用循环:
$res = mysql_query("select * from tableA");
while ($row = mysql_fetch_array($res)) {
echo $row['msg'];
}
Please, don't use mysql_*
functions in new code 。它们不再维护and are officially deprecated 。请参阅red box ?了解 prepared statements相反,并使用 PDO ,或MySQLi -this article将帮助您决定哪个。如果您选择 PDO,here is a good tutorial .
关于php - 从 MySQL 获取多行输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15055037/