Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prev / Next links...

Status
Not open for further replies.

buzzt

Programmer
Joined
Oct 17, 2002
Messages
171
Location
CA
I need to limit the number of results on a page, but would like to make them avaiable through the use of Prev / Next links. I have seen several methods, but they don't seem to work right.

Is there a simple way to do this?
 
How are you producing your results? You basically have a 'while/for' loop (flat index files) or LIMIT (SQL) option.

- - picklefish - -
 
Ok...here's what I have now. It works, except that I never get the last entry int the db (limit 2,2 only shows id #3 and not #4). Sorry it's a bit long...


if (!$limita) $limita=0;
else $limita=$limita;


$result = mysql_query("select * from $type where color like '%$color%' order by 'id' limit $limita,2");
$num_results = mysql_num_rows($result);


if (!$num_results)
{
echo &quot;We're sorry... there do not seem to be any products which match your criteria. Please feel free to search again.\n<br><br>\n&quot;;
}
else
{
echo &quot;Here are the results of your product search...\n<br><br>\n&quot;;
echo &quot;<table width=100% cellpadding=0 cellspacing=0 border=0>\n&quot;;

for ($i=0; $i<$num_results; $i++)
{
$row = mysql_fetch_array($result);
$id = $row[&quot;id&quot;];
$name = $row[&quot;name&quot;];
$desc = $row[&quot;description&quot;];
$color = $row[&quot;color&quot;];
$avail = $row[&quot;avail&quot;];
$image = $row[&quot;image&quot;];

echo &quot;<table width=100% cellpadding=0 cellspacing=0 border=0>\n&quot;;
echo &quot;<tr>\n&quot;;
echo &quot;<td width=15% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;<b>Product Name</b>\n&quot;;
echo &quot;</td>\n<td width=85% height=20 class=\&quot;text\&quot;>\n&quot;;
echo $name . ' ' . $id;
echo &quot;\n</td>\n</tr>\n&quot;;
echo &quot;<tr>\n&quot;;
echo &quot;<td width=15% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;<b>Description</b>\n&quot;;
echo &quot;</td>\n<td width=85% height=20 class=\&quot;text\&quot;>\n&quot;;
echo $desc . &quot;.&quot;;
echo &quot;\n</td>\n</tr>\n&quot;;
echo &quot;<tr>\n&quot;;
echo &quot;<td width=15% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;<b>Colors</b>\n&quot;;
echo &quot;</td>\n<td width=85% height=20 class=\&quot;text\&quot;>\n&quot;;
echo $color;
echo &quot;\n</td>\n</tr>\n&quot;;
echo &quot;<tr>\n&quot;;
echo &quot;<td width=15% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;<b>Availability</b>\n&quot;;
echo &quot;</td>\n<td width=85% height=20 class=\&quot;text\&quot;>\n&quot;;
echo $avail;
echo &quot;\n</td>\n</tr>\n&quot;;
echo &quot;<tr>\n&quot;;
echo &quot;<td width=15% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;<b>Sample Image</b>\n&quot;;
echo &quot;</td>\n<td width=85% height=20 class=\&quot;text\&quot;>\n&quot;;
if ($image == &quot;notavail.gif&quot;)
{
echo &quot;Image Preview Unavailable&quot;;
}
else
{
echo &quot;<a href=\&quot;../graphic/products/&quot; . $image . &quot;\&quot;>Click Here</a>&quot;;
}
echo &quot;\n</td>\n</tr>\n&quot;;
echo &quot;<tr>\n&quot;;
echo &quot;<td width=15% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;<b>Price</b>\n&quot;;
echo &quot;</td>\n<td width=85% height=20 class=\&quot;text\&quot;>\n&quot;;
echo &quot;Call 555-555-5555 for price.&quot;;
echo &quot;\n</td>\n</tr>\n&quot;;
echo &quot;</table>\n<br>\n&quot;;


}
}

//Here is where I set the mysql limit for next results
//page.

$increase = 2;

$limitb = ($limita+$increase);

echo &quot;<a href=\&quot;&quot;.$HTTP_SERVER_VARS['PHP_SELF'].&quot;?limita=&quot;.($limita-$increase).&quot;&&type=$type&&color=$color\&quot;>Previous</a> | &quot;;

echo &quot;<a href=\&quot;&quot;.$HTTP_SERVER_VARS['PHP_SELF'].&quot;?limita=&quot;.$limitb.&quot;&&type=$type&&color=$color\&quot;>Next</a><br><br><br>&quot;;


}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top