Go Back   kirupaForum > Development > Server-Side (PHP, SQL, ASP.NET, etc.)

Reply
 
Thread Tools Display Modes
Old 11-29-2009, 11:50 AM   #1
DigitalWallfare
Registered User
Pagination code not behaving.

Hi all,

I've written code to enable pagination of my search results, but it isnt behaving how I expect it to. It produces 5 results per page, no matter how many I tell it to display, and will not produce the navigation links at all (there are 6 test examples in my database).

Is anyone able to look over my code and tell me where i'm going wrong?

I have error reporting on, but it wont report user error

Here is my code:

PHP Code:
$connection mysql_connect($hostname$username$password);
    if (!
$connection) {
       die(
"A connection to the server could not be established");
    }
/*Select Database */
    
mysql_select_db($database) or die("Database could not be selected!");

/*set variables*/
if (isset($_POST['MerchantType']) && isset($_POST['County'])){
    
$MerchantType $_POST["MerchantType"];
    
$County $_POST["County"];
    echo 
$County "  " $MerchantType;
}
   
    
/* Set current, prev and next page */
$page = (!isset($_GET['page']))? $_GET['page'];  
$prev = ($page 1);
$next = ($page 1);

/* Max results per page */
$max_results 2;

/* Calculate the offset */
$from = (($page $max_results) - $max_results);
/*Query */
$result mysql_query("SELECT * FROM $tablename WHERE County = '$County' AND MerchantType = '$MerchantType'") or die(mysql_error());

$total_results mysql_num_rows($result);

$total_pages ceil($total_results $max_results);

$pagination '';

/* Create a PREV link if there is one */
if($page 1)
{
$pagination .= '<a href="index.php?page='.$prev.'">Previous</a> ';
}

/* Loop through the total pages */
for($i 1$i <= $total_pages$i++)
{
if((
$page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="index.php?page='.$i.'">$i</a>';
}
}

/* Print NEXT link if there is one */
if($page $total_pages)
{
$pagination .= '<a href="index.php?page='.$next.'">Next</a>';
}




while (
$i mysql_fetch_array($result))



while (
$row_details mysql_fetch_array($result)) 
Hopefully someone might be able to help.

Thanks,

Sam
DigitalWallfare is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-29-2009, 09:05 PM   #2
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
Is that the complete script? There isn't any code outputting any row entries, let alone 5.
icio is offline   Reply With Quote
Old 12-06-2009, 07:48 PM   #3
charplus01
Registered User
 
charplus01's Avatar
shouldnt you 'while' loop start at 0 instead of 1? while($i=0)
charplus01 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:19 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com