首页  >  文章  >  后端开发  >  php的查询功能(怎么通过查询条件获取相应表的字段)

php的查询功能(怎么通过查询条件获取相应表的字段)

WBOY
WBOY原创
2016-06-13 12:01:091016浏览

php的查询功能(如何通过查询条件获取相应表的字段)

<?php<br />//获得连接<br />$db = mysql_connect("localhost", "root", "root") or die(mysql_error());<br />//echo "Connected to MySQL<br/>";<br />//连接数据库<br />mysql_select_db("test") or die(mysql_error());<br />//echo "Connected to Database";<br /><br />    //查询数据,并用表格显示出来  <br />	@$checked = $_POST['checked'];<br />	@$result = mysql_query("select * from books",$db);<br />    echo "<table border=1>\n";                                      <br />    echo "<tr><br />	         <td>isbn</td><br />			 <td>author</td><br />			 <td>title</td><br />			 <td>price</td><br />			 ";                                                     <br />    echo "</tr>\n";                                                 <br />    //循环遍历                                                          <br />      while ($myrow = mysql_fetch_row($result)){ <br />	          printf("<tr><br />			               <td>%s</td><br />						   <td>%s</td><br />						   <td>%s</td><br />						   <td>%s</td>", $myrow[0], $myrow[1],$myrow[2],$myrow[3]);<br />            }                                                               <br />         echo "</table>\n";<br />?><br /><html><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><title>无标题文档</title><br /></head><br /><body><br /><form action="" name=""><br/><br />  <br/><br />   <input type="button" value="查询" name="submit"/><br />   <input type="text" name="checked"/><br /></form><br /></body><br /></html>

------解决方案--------------------
result = mysql_query("select * from books where checked=‘$checked’ ");
------解决方案--------------------
if(isset($_POST['checked'])){
@$result = mysql_query("select * from books",$db);
    echo "

\n";                                      
    echo "
             
             
             
             
             ";                                                     
    echo "\n";                                                 
    //循环遍历                                                          
isbn author title price
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn