I get mysql_num_rows() expects parameter 1 to be resource
when I try to bring mysql data to a table. What is the problem with the coding and have used mysql and mysqli correctly? The error is for line $num = mysql_num_rows($result);
. I am pretty sure the problem is that $result but I do not know how to fix it.
<?php
$connection=mysqli_connect("localhost"/*hostname*/,
"username"/*username*/,
"password"/*password*/,
"dbname"/*database name*/);
$query = "SELECT * FROM table";
$result = mysqli_query($query);
$num = mysqli_num_rows($result);
mysqli_close();
$i=0;
while ($i < $num) {
$f1=mysqli_result($result,$i,"rowa");
$f2=mysqli_result($result,$i,"rowb");
$f3=mysqli_result($result,$i,"rowc");
$f4=mysqli_result($result,$i,"rowd");
$f5=mysqli_result($result,$i,"rowe"); ?>
<table>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<td>e</td>
</tr>
<tr>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font>
</td> </tr>
</table>
<?php } ?>
The username, password, database and table name are not the actual names used in the code.