<?php
extract($_GET);
$sql = "SELECT * FROM tablename order by Name DESC";
$sql = "SELECT * FROM tablename where age = "31";
$db = mysql_connect("localhost","root","password");
if (!$db) {
die("");
}
$db_select = mysql_select_db('databasename',$db);
if (!$db_select) {
die("");
}
if (!($result = mysql_query($sql, $db))) {
print("Could not execute query! <br />");
die(mysql_error() . "</body></html>");
} // end if
echo "<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$row['Name']."</td>";
echo "<td>".$row['Age']."</td>";
}
echo "</table>";
mysql_close($db);
?>
在选择名称或年龄时,我应该在哪里添加运行sql语句的name和age的if else语句?姓名和年龄是从不同的列,但在同一个表PHP分离如果其他语句
你的意思我们需要运行这些$ sql中的任何一个?请妥善澄清你的问题。 –
要在选择名称或年龄时运行sql语句 – Synetrix
好的,以及可能的查询字符串键是什么?正如$ _GET ['name']和$ _GET ['age']? –