Forum Topic: mysql/php pagination help?

(129 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

chuckiepower2003

Reply To Post Reply & Quote

Posted at: 4/24/09 04:38 PM

chuckiepower2003 NEUTRAL LEVEL 01

Sign-Up: 09/01/06

Posts: 88

ok i read a tutorial on Pagination in PHP and i got this this but it still displays all of the mysql query
i dont know if i got it dont right cuz it diden tell u much ? can any one help me out.

i wants to load the mysql data that are links and list only 15 prepage and then.
pagination. just a note it show the data but it dont pagination it.

<link rel="stylesheet" href="1.css" type="text/css" />
 <?
include("../config_conn.php");
include("../loaded.php");
?>
<?php
if(!empty($_GET["start"])){
    $start  = $_GET['start'];// To take care global variable if OFF
}else{
    $start   = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
    $start = 0;
}

$eu   = ($start - 0);
$limit           = 15; // No of records to be shown per page.
$whathis      = $eu + $limit;
$back          = $eu - $limit;
$next          = $eu + $limit;

// to check the total number of records
$query         = mysql_query(" SELECT * FROM links ") or die (mysql_error());
$total_rows     = mysql_num_rows($query);

while($linelink2=mysql_fetch_array($resultlink2)) {
echo "<table align=center width=550>"; echo "<tr>
		<td>$linelink2[linktitle]</td>
		<td><a class=\"link1\" href=\"<?=\$linelink2[linkurl]?>\" target=\"_blank\"><?=\$linelink2[linkurl]?></a></td>
	</tr> ";
    echo "</table>";
}


//select the record with limitation   SELECT * FROM `links` WHERE linkid ORDER BY RAND() LIMIT 15
$query         = mysql_query(" SELECT * FROM `links` limit $eu, $limit") or die (mysql_error());
echo "<table align=center width=550>";



//code for previous
if($back >=0) {
echo "<a class=\"pagination\" href='test.php?start=$back'><font face='Verdana' size='2'>PREV</font></a>&nbsp;&nbsp;";
}

//code for the number of page with links
$i     = 0;
$x    = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
    echo "<a class=\"pagination\" href='test.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else {
    echo "<font face='Verdana' size='4' color=red>$x</font>";

} // Current page is not displayed as link and given font color red

$x    = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a class=\"pagination\" href='test.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}
?>

None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 4/25/09 12:33 AM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,284

Your SQL query must be capitalized.

$query         = mysql_query(" SELECT * FROM `links` limit $eu, $limit") or die (mysql_error());

That line...needs fixed with the spacing anyway...but needs to be this.

$query  = mysql_query(" SELECT * FROM `links` LIMIT $eu, $limit") or die (mysql_error());

None

chuckiepower2003

Reply To Post Reply & Quote

Posted at: 4/25/09 03:47 AM

chuckiepower2003 NEUTRAL LEVEL 01

Sign-Up: 09/01/06

Posts: 88

$query = mysql_query(" SELECT * FROM `links` limit $eu, $limit") or die (mysql_error());

That line...needs fixed with the spacing anyway...but needs to be this.

$query = mysql_query(" SELECT * FROM `links` LIMIT $eu, $limit") or die (mysql_error());

it try but it just show all of the links?


None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 4/26/09 01:45 AM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,284

You're doing it backwards here.

// to check the total number of records
$query         = mysql_query(" SELECT * FROM links ") or die (mysql_error());
$total_rows     = mysql_num_rows($query);

while($linelink2=mysql_fetch_array($resultlink2)) {
echo "<table align=center width=550>"; echo "<tr>
		<td>$linelink2[linktitle]</td>
		<td><a class=\"link1\" href=\"<?=\$linelink2[linkurl]?>\" target=\"_blank\"><?=\$linelink2[linkurl]?></a></td>
	</tr> ";
    echo "</table>";
}


//select the record with limitation   SELECT * FROM `links` WHERE linkid ORDER BY RAND() LIMIT 15
$query         = mysql_query(" SELECT * FROM `links` limit $eu, $limit") or die (mysql_error());
echo "<table align=center width=550>";

You're putting out all the HTML before you're limiting anything.


All times are Eastern Standard Time (GMT -5) | Current Time: 09:16 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!