Current location: Hot Scripts Forums » Programming Languages » PHP » problem printing mysql data by "x rows/page"


problem printing mysql data by "x rows/page"

Reply
  #1 (permalink)  
Old 07-29-04, 12:23 PM
abtimoteo abtimoteo is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Question problem printing mysql data by "x rows/page"

hi, everybody!

1. i have mysql data with several rows.

2. i want to print/display data by "x rows/page."

3. i tried to do it with the following script:

function navDat ($ThisScript = " ", $StartingPage = 0, $Thistbl)
{
global $PHP_SELF;

if (empty ($ThisScript))
{
$ThisScript = $PHP_SELF;
}

if (empty ($StartingPage))
{
$StartingPage = 0;
}

PAGE_LIMIT = 2;

$xEntriestoPrint = PAGE_LIMIT;

$Thistbl; // Undefined. Value to be supplied in the function call.

$ThisResult = mysql_query ("select count(*) from $Thistbl");

list ($xRows) = mysql_fetch_array ($ThisResult);

print "<p>\n";

if ($StartingPage > 0)
{
print "<a href=\"$ThisScript?StartingPage=".($StartingPage - $xEntriestoPrint)."\">&lt;&lt;Previous Entries</a> &nbsp;&nbsp; ";
}

if (($StartingPage + $xEntriestoPrint) < $xRows)
{
echo "&nbsp;&nbsp;<a href=\"" . $PHP_SELF . "?StartingPage=" . ($StartingPage + $xEntriestoPrint) . "\">Next Entries&gt;&gt;</a>";
}

print "</p>\n";

}

4. from a script that prints mysql data by two, i call the above with:

$Thistbl = ThisDataSource;

navDat ($ThisScript, $StartingPage, $Thistbl);

5. THE PROBLEM: while the "previous" and "next" links are being printed, the content of the page remains the same? only the first two entries of the mysql data/table are being printed, instead of the script printing rows 0-1, 2-3, 4-5 ...
Reply With Quote
  #2 (permalink)  
Old 07-30-04, 07:55 PM
tylerc tylerc is offline
Newbie Coder
 
Join Date: May 2004
Location: Canada
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Cool

Um, this is how you can print certain number of results per page.

URL: http://www.demo.com/print.php?page=3&results_page=30
PHP Code:

<?php


/*

This is printing 30 results per page and we are on the third page

*/

// Grab Query Strings //
$results_page $_GET['results_page'];
$page $_GET['page'];

/// This line says where to start gettings results, will be 31 //

$start_results $page $results_page 1// X = 91 //

$sql "SELECT columns FROM table WHERE column='something here' LIMIT $start_results$results_page";

$query mysql_query($sql);

while(
$data mysql_fetch_array($query)) {
echo 
$data[0];
}

echo 
"<a href="print.php?page=$page 1&results_page=$results_page">Last Page</a> | <a href="print.php?page=$page 1&results_page=$results_page">Next Page</a><p>";

?>
This is how you do a limit correctly

PHP Code:



$sql 
"SELECT columns FROM table WHERE column='something here' LIMIT /// Where to Start Printing ///, /// # of results to get ///";

Example:

$sql "SELECT log_action FROM logs WHERE date='$date' LIMIT 200, 20";

This will start at result 201 then retrieve the values al the way upto 220. 
Hope this helps!
__________________
-Tyler
RuneGuide Owner/Manager

Runescape Stats:
http://www.rsbandb.com/sig/sigs/n/nexon89.png
Reply With Quote
Reply

Bookmarks


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem getting data from DataGrid on update petersza ASP.NET 5 10-19-04 11:37 PM
Is it Possible to export data from a web page with no admin access to mySQL? phpseth PHP 1 06-04-04 10:58 AM
mysql Repetative data Mr. L PHP 2 05-14-04 12:12 PM
Load Data Infile Problem (MySQL) Shaky2 PHP 1 03-26-04 04:48 PM


All times are GMT -5. The time now is 04:15 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.