关于查询mysql字段并输出
表A:
id title
---------------------------------
10 测试
11 你好
12 很好
13 非常好
PHP输出:
PHP code
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->$test['title'] = array(
array('md' => '测试'),
array('md' => '你好'),
array('md' => '很好'),
array('md' => '非常好'),
);
请教如果想查询mysql数据库中,有关于“测试、你好、很好、非常好”
的id值,mysql查询语句应该如何写?类似:
SQL code
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->SELECT * FROM A where A.title = "测试" or A.title = "你好" or A.title = "很好" or A.title = "非常好" limit 0,10
这样子的查询语句,这种语句只能列出数据库中匹配的数据,我只想让他输出ID字段,我应该怎么做?
------解决方案--------------------SELECT * FROM A where A.title in ('测试','你好','很好','非常好') limit 0,10
------解决方案--------------------用PHP输出比较简单.
1.连接数据库.
2.执行select
3.mysql_fetch_array
下面的不打了。.....自己google多得是
------解决方案--------------------
虽然你不在了但是我还是写出来,分要给我:
$sql="SELECT id,title FROM A where title in ('测试','你好','很好','非常好') limit 0,10";
$link = mysql_connect('127.0.0.1', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mysql_database",$link);
mysql_query("set names utf8");
$res = mysql_query($sql);
while($info = mysql_fetch_assoc($res)){
echo "title为".$info['title']."的id号为".$info['id']."
";
}
over;记得给分!!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn