數(shù)據(jù)庫中有一個表test為:id name age $sql="select * from test where age=20";$result=mysql_query($sql);echo "<table border='1' cellspacing=0px><tr><th>id</th><th>name</th><th>age</th></tr>";while ($row=mysql_fetch_array($result)) {echo "<tr>";echo "<td>".$row['id']."</td>";echo "<td>".$row['name']."</td>";echo "<td>".$row['age']."</td>";echo "</tr>";}echo "</table>";
1 回答
守著星空守著你
TA貢獻1799條經(jīng)驗 獲得超8個贊
你使用的函數(shù)就是單條的。請換成mysql_fetch_field
<?php$con = mysql_connect("localhost", "hello", "321");if (!$con) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("test_db",$con); $sql = "SELECT * from Person";$result = mysql_query($sql,$con); while ($property = mysql_fetch_field($result)) { echo "Field name: " . $property->name . "<br />"; echo "Table name: " . $property->table . "<br />"; echo "Default value: " . $property->def . "<br />"; echo "Max length: " . $property->max_length . "<br />"; echo "Not NULL: " . $property->not_null . "<br />"; echo "Primary Key: " . $property->primary_key . "<br />"; echo "Unique Key: " . $property->unique_key . "<br />"; echo "Mutliple Key: " . $property->multiple_key . "<br />"; echo "Numeric Field: " . $property->numeric . "<br />"; echo "BLOB: " . $property->blob . "<br />"; echo "Field Type: " . $property->type . "<br />"; echo "Unsigned: " . $property->unsigned . "<br />"; echo "Zero-filled: " . $property->zerofill . "<br /><br />"; } mysql_close($con);?> |
添加回答
舉報
0/150
提交
取消
