Hello:
I can fix a value (how many rows per page) for display records.But when I use a pull down menu to choose for this."Division by zero" error occur.Here's my code:
<?php
mysql_connect("host","usrname",passwd")
or die("fail");
mysql_select_db("database"); ?>
<form action="<?echo $PHP_SELF?>" method=post>
<select name="limit">
<option value="2">2 per pages
<option value="4">4 per pages
<option value="6">6 per pages
<option value="8">8 per pages
</select>
<input type="Submit" name="submit"
value="set">
</form>
<?
$query_rows=mysql_query("select * from pet");
$numrows=mysql_num_rows($query_rows);
if (empty($offset))
{$offset=0; }
$result=mysql_query("select * from pet limit $offset,$limit"); ?>
<table border=0 cellpadding=4 cellspacing=1>
<tr><th bgcolor="#6699ff">Name</th><th bgcolor="#6699ff">Owner</th>
<th bgcolor="#6699ff">Species</th>
<th bgcolor="#6699ff">Sex</th>
<th bgcolor="#6699ff">Birth</th>
<th bgcolor="#6699ff">Death</th></tr>
<? while ($post=mysql_fetch_array($result))
{ ?>
<tr><td bgcolor="#66ccff"><?echo $post
['name']?></td>
<td bgcolor="#66ccff"><?echo $post
['owner']?></td>
<td bgcolor="#66ccff"><?echo $post
['species']?></td>
<td bgcolor="#66ccff"><?echo $post
['sex']?></td>
<td bgcolor="#66ccff"><?echo $post
['birth']?></td>
<td bgcolor="#66ccff"><?echo $post
['death']?></td></tr>
<? } ?>
</table>
<?
$pages=intval($numrows/$limit);
if ($numrows%$limit)
{$pages++;}
if ($offset>0)
{
$prevoffset=$offset-$limit; ?>
<a href="<?echo $PHP_SELF ?>?offset=<?echo $prevoffset ?>">prev</a>
<? }
for ($i=1;$i<=$pages;$i++)
{
$newoffset=$limit*($i-1); ?>
<a href="<?echo $PHP_SELF?>?offset=<?echo $newoffset ?>"><? echo $i?></a>
<? }
if (!(($offset/$limit)==$pages) && $pages!=1 )
{
$newoffset=$offset+$limit; ?>
<a href="<?echo $PHP_SELF ?>?offset=<?echo $newoffset ?>">next</a>
<? } ?>
I have tried casting (integer)$limit and check condition
if($limit != 0)
{
.....
.....
}
but fail.So would anyone tell me how can I use value selected from the form for further processing.Thx