//没有complie error,不过表格打出来时空白的,没有result,可是$num_rows是12个,请各位高手看看,帮忙解决一下。<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm']; if (!$searchtype || !$searchterm)
{
echo 'You did not enter search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
} $database = new mysqli('localhost', 'root', '', 'book'); if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again';
exit;
}
?>
<table border ="1">
<tr>
<td> Author </td>
<td> Title </td>
<td> ISBN </td>
<td> Price</td>
</tr>
<?php
$query = "select * from detail";
$result = $database->query($query);
$rows_count = $result->num_rows;
printf ("Number of books are selected:%d",$rows_count);
while ($rows = $result->fetch_assoc()!== NULL)
{
//就是这一段输出表格print_r($row);
echo "
<tr>
<td> {$row['author']} </td>
<td> {$row['title']} </td>
<td> {$row['isbn']} </td>
<td> {$row['price']} </td>
</tr>";
}
echo '</table>';
?>
</body>
</html>
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm']; if (!$searchtype || !$searchterm)
{
echo 'You did not enter search details. Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
} $database = new mysqli('localhost', 'root', '', 'book'); if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again';
exit;
}
?>
<table border ="1">
<tr>
<td> Author </td>
<td> Title </td>
<td> ISBN </td>
<td> Price</td>
</tr>
<?php
$query = "select * from detail";
$result = $database->query($query);
$rows_count = $result->num_rows;
printf ("Number of books are selected:%d",$rows_count);
while ($rows = $result->fetch_assoc()!== NULL)
{
//就是这一段输出表格print_r($row);
echo "
<tr>
<td> {$row['author']} </td>
<td> {$row['title']} </td>
<td> {$row['isbn']} </td>
<td> {$row['price']} </td>
</tr>";
}
echo '</table>';
?>
</body>
</html>
后面是{$row['author']} 少了个S
谢谢你的指点,我已经加好了,不过还是不行,没东西打出来。能否再看看那里错了。
echo '<tr>';
echo " <td> {$row['author']} </td>";
echo"......";
这样试下 print_r能输出数组是吧 那就是echo出问题了