Warning: mysql_fetch_assoc(): 4 is not a valid MySQL result resource
hi,
i coding manually in php time have tried code dreamvaver. , getting warning plus 1 record displaying.
here code:
<?php require_once('connections/connection.php'); ?>
<?php
$maxrows_storeresults = 10;
$pagenum_storeresults = 0;
if (isset($_get['pagenum_storeresults'])) {
$pagenum_storeresults = $_get['pagenum_storeresults'];
}
$startrow_storeresults = $pagenum_storeresults * $maxrows_storeresults;
mysql_select_db($database_connection, $connection);
$query_storeresults = "select str_id, str_name, sale_begin, sale_end store";
$query_limit_storeresults = sprintf("%s limit %d, %d", $query_storeresults, $startrow_storeresults, $maxrows_storeresults);
$storeresults = mysql_query($query_limit_storeresults, $connection) or die(mysql_error());
$row_storeresults = mysql_fetch_assoc($storeresults);
if (isset($_get['totalrows_storeresults'])) {
$totalrows_storeresults = $_get['totalrows_storeresults'];
} else {
$all_storeresults = mysql_query($query_storeresults);
$totalrows_storeresults = mysql_num_rows($all_storeresults);
}
$totalpages_storeresults = ceil($totalrows_storeresults/$maxrows_storeresults)-1;
mysql_free_result($storeresults);
?>
<table border="0">
<tr>
<td>str_id</td>
<td>str_name</td>
<td>sale_begin</td>
<td>sale_end</td>
</tr>
<?php { ?>
<tr>
<td><?php echo $row_storeresults['str_id']; ?></td>
<td><?php echo $row_storeresults['str_name']; ?></td>
<td><?php echo $row_storeresults['sale_begin']; ?></td>
<td><?php echo $row_storeresults['sale_end']; ?></td>
</tr>
<?php } while ($row_storeresults = mysql_fetch_assoc($storeresults)); ?>
</table>
this out put m getting:
| str_id | str_name | sale_begin | sale_end |
| 1 | abc | 2010-07-05 20:41:59 | 2010-07-12 20:41:38 |
the problem lies here:
mysql_free_result($storeresults);
?>
<table border="0">
<tr>
<td>str_id</td>
<td>str_name</td>
<td>sale_begin</td>
<td>sale_end</td>
</tr>
<?php { ?>
<tr>
<td><?php echo $row_storeresults['str_id']; ?></td>
<td><?php echo $row_storeresults['str_name']; ?></td>
<td><?php echo $row_storeresults['sale_begin']; ?></td>
<td><?php echo $row_storeresults['sale_end']; ?></td>
</tr>
<?php } while ($row_storeresults = mysql_fetch_assoc($storeresults)); ?>
</table>
mysql_free_result() destroying recordset resource before repeat region.
if delete mysql_free_result($storeresults); should work.
dreamweaver puts mysql_free_result() below closing </html> tag, looks though have accidentally moved it. when working server behaviors, it's important remove them cleanly clicking minus button in server behaviors panel. otherwise, can left stray bits of code cause problems this.
More discussions in Develop server-side applications in Dreamweaver
adobe
Comments
Post a Comment