Next Previous PHP/mySQL functionality
I'm looking for a PHP/mySQL script with this kind of display functionality:
// next and previous buttons
NEXT Displaying - results 33 - 40 of 1874 PREVIOUS
Thanks,
TM
I'm looking for a PHP/mySQL script with this kind of display functionality:
// next and previous buttons
NEXT Displaying - results 33 - 40 of 1874 PREVIOUS
Thanks,
TM
Busy posted this at 21:45 — 6th November 2003.
He has: 6,151 posts
Joined: May 2001
try hotscripts but you'll have to modify whatever you find to suit your needs, sometimes it's easier to just make something.
somethign like:
select all from db
count how many there are
variable for how many to a page
if total is under the variable dont display next
if first bunch < variable no previous link
kinda thing
TonyMontana posted this at 22:17 — 6th November 2003.
They have: 218 posts
Joined: Apr 2001
I built one in Flash/php and I can toggle between next and previous okay, but other patterns break the script. If someone has the specific actions for their next and previous buttons, I'd like to check it out.
Thanks,
TM
Mark Hensler posted this at 01:07 — 7th November 2003.
He has: 4,048 posts
Joined: Aug 2000
I know I've answered this question before, but I just looked through 150 of 500 search results and I didn't find anything.
Do you have any existing code we can work from?
Mark Hensler
If there is no answer on Google, then there is no question.
TonyMontana posted this at 05:59 — 7th November 2003.
They have: 218 posts
Joined: Apr 2001
Ok, here's a code example. This is from an example I found online. It displays the buttons ok, but no content is generated from the relevent rows in the table.
// limit value for number of records to be shown per page
// query database to find total number of records to display
$limit = 5;
// $query_count = "select * from ".$prefix."store_inventory where (description like '%$search%' or title like '%$search%')";
// root query
$query_count = "select * from itemTable WHERE cID='sumNum";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page))
// if null, start at beginning
$page = 1;
// total minus viewable limit
$limitvalue = $page * $limit - ($limit);
echo "LimitValue : " . $limitvalue;
$query = "select * from itemTable LIMIT $limitvalue, $limit ";
$iXML = mysql_query($query) or die("Error: " . mysql_error());
// number of rows in query, limit 8. Starting at page one
$count_result = mysql_num_rows($iXML);
// no content is generated, the index starts at the incorrect index
for ($j=0;$j<$count_result;$j++){
$ar = mysql_fetch_array($iXML);
echo "<br>" . $ar["itemIndex. " dex";
}
// Display links at the top to indicate current page and number of pages displayed
$numofpages = ceil($totalrows / $limit);
echo"<br><p><b>$totalrows</b> result(s) for: \"search\"</p>";
$from=$limit*$page-$limit+1;
$to=$from + $count_result-1;
// start 123 next>> table
echo "<table align=\"center\" width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"left\">";
if($numofpages>1){
echo"Showing: $from - $to</td><td width=\"50%\" bgcolor=\"$bg_colour\" align=\"right\"><b>Go to page:</b> ";
}
// display previous link if page is not 1
if($page != 1){
$pageprev = $page - 1;
// echo("<a href=\"$PHP_SELF?page=$pageprev&search=$search\"><< PREV</a> ");
echo("<a href=\"$PHP_SELF?page=$pageprev\"><< PREV</a> ");
}
/*
// display page nos if not 1
for($i = 1; $i <= $numofpages; $i++){
if($numofpages>1){
if($i == $page)
echo(" ".$i." ");
else
echo(" <a href=\"$PHP_SELF?page=$i&search=$search\">$i</a> ");
}}
*/
// display next page link if there is more than one
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
// echo("<a href=\"$PHP_SELF?page=$pagenext&search=$search\">NEXT >></a>");
echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT >></a>");
}
// end 123 next>> table
echo"</td></tr></table><br>";
?>
An example of similar functionality I'm trying to achieve is at: lodgingchannel.com
Thanks, and hope you can help
TM
Mark Hensler posted this at 07:11 — 7th November 2003.
He has: 4,048 posts
Joined: Aug 2000
SWAP OUT:
<?php
// no content is generated, the index starts at the incorrect index
for ($j=0;$j<$count_result;$j++){
$ar = mysql_fetch_array($iXML);
echo \"<br>\" . $ar[\"itemIndex. \" dex\";
}
?>
REPLACE WITH:
<?php
echo \"<table>\n\";
echo \"<tr>\n\";
for ($i=0; $i<mysql_num_fields($iXML); $i++) {
$field = mysql_fetch_field($iXML, $i);
echo \"<td><b>\".$field->name.\"</b></td>\n\";
}
echo \"</tr>\n\";
while ($ar = mysql_fetch_array($iXML)) {
echo \"<tr>\n\";
foreach ($ar as $key=>$val) {
echo \"<td>$val</td>\n\";
}
echo \"</tr>\n\";
}
echo \"</table>\n\";
?>
Mark Hensler
If there is no answer on Google, then there is no question.
TonyMontana posted this at 07:49 — 7th November 2003.
They have: 218 posts
Joined: Apr 2001
That's cool. But how would I modify the script if I want to select and display results from rows other than the first few indexes, which is occuring with this line currently:
$query = "select * from itemTable LIMIT $limitvalue, $limit ";
If a user presses 'next', can $limitvalue be changed to a pointer to the correct index in an item table, wherever that may be?
If the category I'm selecting has an index of 87 for instance, and I want to select and display results from it's child item table:
$cID = 87;
$query_count = "select * from itemTable WHERE catsID='$cID'";
There's a chance nothing will be returned if I use this line:
$query = "select * from itemTable LIMIT $limitvalue, $limit ";
...in the case $limitvalue doesn't exist, which would be a problem because I'm trying to generate a photo url from one of the columns.
If I can find a way to get some reliable algorithms together and make this work, that would be great.
Thanks,
TM
Mark Hensler posted this at 18:09 — 7th November 2003.
He has: 4,048 posts
Joined: Aug 2000
I'm sorry. I'm lost. I don't understand what your describing.
Is this the solution you're looking for:
$query = "select * from itemTable WHERE catsID='$cID' LIMIT $limitvalue, $limit ";
Mark Hensler
If there is no answer on Google, then there is no question.
TonyMontana posted this at 19:25 — 7th November 2003.
They have: 218 posts
Joined: Apr 2001
Is this the solution you're looking for:
$query = "select * from itemTable WHERE catsID='$cID' LIMIT $limitvalue, $limit ";
Yes, . I changed that line and boom, I moved through 18 records in a 3d nav in flash, with a limit of 8 items at a time.
Thanks,
TM
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.