查询无循环 [英] query without loop
本文介绍了查询无循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从数据库记录中查询单个帖子(标题,正文,日期)
I want to query from the db records for a single post (title, body, date)
例如,我有查询。
$ query ='SELECT * FROM posts where id = $ post_id';
从该查询中,我如何可以在没有一段时间或foreach循环的情况下回显标题?
From that query how can I echo the title for instance without a while or foreach loop?
推荐答案
您可以调用mysql_fetch_assoc()(或任何类似的函数)之一。像这样:
You can just call mysql_fetch_assoc() (or any similar function) one. Like this:
$sql = "SELECT * FROM table";
$row = mysql_fetch_assoc( mysql_query($sql) );
echo $row['title'];
这是通过MySQL函数执行此操作的最简单,最易读的方式。
This is the easiest and most readable way to do this with the MySQL functions.
这篇关于查询无循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文