php的查詢功能(如何通過查詢條件獲取相應(yīng)表的字段)
<?php<br />//獲得連接<br />$db = mysql_connect("localhost", "root", "root") or die(mysql_error());<br />//echo "Connected to MySQL<br/>";<br />//連接數(shù)據(jù)庫<br />mysql_select_db("test") or die(mysql_error());<br />//echo "Connected to Database";<br /><br /> //查詢數(shù)據(jù),并用表格顯示出來 <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 /> //循環(huán)遍歷 <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>無標(biāo)題文檔</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?"
?????????????isbn |
?????????????author |
?????????????title |
?????????????price |
?????????????";?????????????????????????????????????????????????????
????echo?"
\n";?????????????????????????????????????????????????
????//循環(huán)遍歷??????????????????????????????????????????????????????????