php的查询功能(如何通过查询条件获取相应表的字段) result = mysql_query("select * from books where checked=‘$checked’ "); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 比如输入要查询的isbn号,然后确定,在下方输出符合条件的查询结果。 result = mysql_query("select * from books where checked=‘$checked’ ");这个我试了一下,出现以下错误还有一个问题要请教是如何是要先查询之后才显示表要显示的结果。 ... where 字段='$checked' //字段换成你实际的字段 if(isset($_POST['checked'])){@$result = mysql_query("select * from books",$db); echo "<table border=1>\n"; echo "<tr> <td>isbn</td> <td>author</td> <td>title</td> <td>price</td> "; echo "</tr>\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "</table>\n";} 谢谢jordan102,那请问如何通过查询条件,然后在同个页面下输出符合查询条件的表呢?这是我的表 我试了jordan102的代码,也不知道我添加if(isset($_POST['checked'])){.......}这段代码的位置对不对。我按了下查询的按钮,但是没反应。代码如下<?php//获得连接$db = mysql_connect("localhost", "root", "root") or die(mysql_error());//echo "Connected to MySQL<br/>";//连接数据库mysql_select_db("test") or die(mysql_error());//echo "Connected to Database"; //查询数据,并用表格显示出来 @$checked = $_POST['checked'];// @$result = mysql_query("select * from books",$db);// @$result = mysql_query("select * from books where isbn='$checked' "); if(isset($_POST['checked'])){ @$result = mysql_query("select * from books",$db); echo "<table border=1>\n"; echo "<tr> <td>isbn</td> <td>author</td> <td>title</td> <td>price</td> "; echo "</tr>\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "</table>\n";} ?><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><form action="" name=""><br/> <br/> <input type="button" value="查询" name="submit"/> <input type="text" name="checked"/></form></body></html> @$result = mysql_query("select * from books where isbn='$checked'",$db); <input type="submit" value="查询" name="submit"/> @jordan102我试了下@$result = mysql_query("select * from books where isbn='$checked'",$db); 但是点了按钮还是不行。 这句<input type="submit" value="查询" name="submit"/>我试了,但是我输入books的isbn到输入框的时候,点击查询,还是查不到isbn=1的对应的全部内容。 $result = mysql_query("select * from books",$db);条件都不加,还算是条件查询吗? 回复xuzuning,不好意思!忘了加。 <form action="" name="" method="post"><br/> 回复Jordan120,还是没有表显示。 回复xuzuning,请问这句不是@$result = mysql_query("select * from books where isbn='$checked'",$db);通过查询isbn的编号然后判断符合条件的来输出表。 <?php//获得连接$db = mysql_connect("localhost", "root", "root") or die(mysql_error());//echo "Connected to MySQL<br/>";//连接数据库mysql_select_db("test") or die(mysql_error());//echo "Connected to Database"; //查询数据,并用表格显示出来 // @$checked = $_POST['checked'];// @$result = mysql_query("select * from books",$db);// @$result = mysql_query("select * from books where isbn='$checked' "); if(isset($_POST['checked'])){ @$result = mysql_query("select * from books where isbn='$checked'",$db); echo "<table border=1>\n"; echo "<tr> <td>isbn</td> <td>author</td> <td>title</td> <td>price</td> "; echo "</tr>\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "</table>\n";} ?><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><form action="" name="post"><br/> <br/> <input type="submit" value="查询" name="submit"/> <input type="text" name="checked"/></form></body></html> @$result = mysql_query("select * from books where isbn='$checked'",$db);在哪里赋值的??? 嗦嘎,我在#18标红了你还抄错。<form action="" method="post"> <?php//获得连接$db = mysql_connect("localhost", "root", "rDSzPnhnDJCAHYuj") or die(mysql_error());//echo "Connected to MySQL<br/>";//连接数据库mysql_select_db("test") or die(mysql_error());//echo "Connected to Database";//查询数据,并用表格显示出来// @$checked = $_POST['checked'];// @$result = mysql_query("select * from books",$db);// @$result = mysql_query("select * from books where isbn='$checked' ");if(isset($_POST['checked'])){ $checked=$_POST['checked']; @$result = mysql_query("select * from books where isbn='$checked'",$db); echo "<table border=1>\n"; echo "<tr> <td>isbn</td> <td>author</td> <td>title</td> <td>price</td> "; echo "</tr>\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "</table>\n";}?><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title></head><body><form action="" name="post" method="post"><br/> <br/> <input type="submit" value="查询" name="submit"/> <input type="text" name="checked"/></form></body></html> <?php//获得连接$db = mysql_connect("localhost", "root", "root") or die(mysql_error());//echo "Connected to MySQL<br/>";//连接数据库mysql_select_db("test") or die(mysql_error());//echo "Connected to Database";//查询数据,并用表格显示出来// @$checked = $_POST['checked'];// @$result = mysql_query("select * from books",$db);// @$result = mysql_query("select * from books where isbn='$checked' ");if(isset($_POST['checked'])){ $checked=$_POST['checked']; @$result = mysql_query("select * from books where isbn='$checked'",$db); echo "<table border=1>\n"; echo "<tr> <td>isbn</td> <td>author</td> <td>title</td> <td>price</td> "; echo "</tr>\n"; //循环遍历 while ($myrow = mysql_fetch_row($result)){ printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]); } echo "</table>\n";}?><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title></head><body><form action="" name="post" method="post"><br/> <br/> <input type="submit" value="查询" name="submit"/> <input type="text" name="checked"/></form></body></html> 回复qxhaidao、jordan102:折腾了两位一个下午,qxhaidao的代码运行成功,jordan那个只显示了表头。我会给两位加分的,实在谢谢了! mysql用控制台突然无法登陆了 1045错误 php 动态表单的生成和提交 菜鸟求助:wamp php文件中如何确定一个数据库已经存在? 求一sql语句 php 中 mysql 外键约束的问题 求一个校验码代码 php页面在显示时总是有“-->”和“<!--”这两个符号显示。如何去掉啊?>??? 上传图片的困惑 如何查找字符串中中文字符所在的位置? 在一行语句里调用一个类的多个方法,该怎么写? 同样的代码,为什么浏览器按F12后看到的代码有如此差距 关于session的过期问题
还有一个问题要请教是如何是要先查询之后才显示表要显示的结果。
@$result = mysql_query("select * from books",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
}
这是我的表
我按了下查询的按钮,但是没反应。代码如下<?php
//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
//echo "Connected to MySQL<br/>";
//连接数据库
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database"; //查询数据,并用表格显示出来
@$checked = $_POST['checked'];
// @$result = mysql_query("select * from books",$db);
// @$result = mysql_query("select * from books where isbn='$checked' ");
if(isset($_POST['checked'])){
@$result = mysql_query("select * from books",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="" name=""><br/>
<br/>
<input type="button" value="查询" name="submit"/>
<input type="text" name="checked"/>
</form>
</body>
</html>
条件都不加,还算是条件查询吗?
//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
//echo "Connected to MySQL<br/>";
//连接数据库
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database"; //查询数据,并用表格显示出来
// @$checked = $_POST['checked'];
// @$result = mysql_query("select * from books",$db);
// @$result = mysql_query("select * from books where isbn='$checked' ");
if(isset($_POST['checked'])){
@$result = mysql_query("select * from books where isbn='$checked'",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="" name="post"><br/>
<br/>
<input type="submit" value="查询" name="submit"/>
<input type="text" name="checked"/>
</form>
</body>
</html>
在哪里赋值的???
<form action="" method="post">
//获得连接
$db = mysql_connect("localhost", "root", "rDSzPnhnDJCAHYuj") or die(mysql_error());
//echo "Connected to MySQL<br/>";
//连接数据库
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database";//查询数据,并用表格显示出来
// @$checked = $_POST['checked'];
// @$result = mysql_query("select * from books",$db);
// @$result = mysql_query("select * from books where isbn='$checked' ");
if(isset($_POST['checked'])){
$checked=$_POST['checked'];
@$result = mysql_query("select * from books where isbn='$checked'",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="" name="post" method="post"><br/>
<br/>
<input type="submit" value="查询" name="submit"/>
<input type="text" name="checked"/>
</form>
</body>
</html>
//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
//echo "Connected to MySQL<br/>";
//连接数据库
mysql_select_db("test") or die(mysql_error());
//echo "Connected to Database";//查询数据,并用表格显示出来
// @$checked = $_POST['checked'];
// @$result = mysql_query("select * from books",$db);
// @$result = mysql_query("select * from books where isbn='$checked' ");
if(isset($_POST['checked'])){
$checked=$_POST['checked'];
@$result = mysql_query("select * from books where isbn='$checked'",$db);
echo "<table border=1>\n";
echo "<tr>
<td>isbn</td>
<td>author</td>
<td>title</td>
<td>price</td>
";
echo "</tr>\n";
//循环遍历
while ($myrow = mysql_fetch_row($result)){
printf("<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);
}
echo "</table>\n";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="" name="post" method="post"><br/>
<br/>
<input type="submit" value="查询" name="submit"/>
<input type="text" name="checked"/>
</form>
</body>
</html>