php打印数组的10个结果
我有个问题想问你们。 我正在尝试打印一个数组,其中它将根据用户显示表中的 10 个值。 这是我到目前为止所拥有的,它只显示第一行,
session_start();
// Retrieve all the data from the table
$result = mysql_query("SELECT name,location,login_id FROM table WHERE login_id = $user[login_id]")
or die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo " name ".$row['name'];
echo " located ".$row['location'];
...... 如何显示前 10 行? 我们将不胜感激。 感谢您的阅读。
i have a question for you guys.
im trying to print an array where it would display 10 values of the table acording to user.
this is what i have so far and it displays only the first row,
session_start();
// Retrieve all the data from the table
$result = mysql_query("SELECT name,location,login_id FROM table WHERE login_id = $user[login_id]")
or die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
echo " name ".$row['name'];
echo " located ".$row['location'];
.....
how can i display the first 10 rows?
help would be apreciated.
thank you for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还将“limit 10”添加到查询中。
also add "limit 10" to the query.
仅当您的login_id不唯一并且多行可以具有相同的login_id时,这才有效
And This will work only if your login_id is not unique and multiple rows can have the same login_id
您必须重复调用 mysql_fetch_array 才能从结果集中获取所有行:
请参阅文档中的更多示例。
如果您确实只想获取前 10 行,请查看 @Yasser Souri 的回答(不过你仍然需要循环)。
You have to call
mysql_fetch_array
repeatedly to get all the row from the result set:See further examples in the documentation.
If you really want to get only the first 10 rows, have a look at @Yasser Souri's answer (you still have to loop though).