更改此:
$result = mysql_query("$query");
这样:
$result = mysql_query($query);
,并根据需要获取尽可能多的数据:
while ($row = mysql_fetch_array ($result)){
echo"<tr>" . $row['student_id'] . "</tr>";
echo"<tr>" . $row['student_name'] . "</tr>";
echo"<tr>" . $row['student_class'] . "</tr>";
}
注:我有使用假人列名,更换student_name
, student_class
你所拥有的列在表中
编辑:
正如预期的那样,一旦你得到了这些问题的解决。移动到mysqli
和喜欢的东西开始:
connection.php:
<?php
$con = mysqli_connect("localhost","root", "", "your_db_name_here");
if(mysqli_connect_errno())
{
echo "Failed to connect" . mysqli_connect_error();
}
?>
的index.php:
<?php
// if (isset($_POST['your_submit_button_name_here'])) {
include('connection.php');
$query = "SELECT * FROM result";
$result = mysqli_query($con, $query);
if($result){
while ($row = mysqli_fetch_assoc ($result)){
echo"<tr>" . $row['student_id'] . "</tr>";
echo"<tr>" . $row['student_name'] . "</tr>";
echo"<tr>" . $row['student_class'] . "</tr>";
}}
else
echo"Query Failed.";
// }
?>
更多更深入的研究:
PHP Manual: MySQL Improved Extension
PHP Manual: PHP Data Objects
请避免使用_deprecated_ mysql函数并移至“mysqli”或“PDO” – user5173426