Jump to content

limit results to 5/page


flemingmike

Recommended Posts

hi, how can i make results 5 per page?  right now my page is way too long.  here is my pages code:

 

<?


include("./includes/incglobal.php");

if($tourney[id]){
$thistourney=mysql_query("SELECT id,name,ladderon,size,enddate,signupdate,prize,details,date FROM tourneys WHERE id='$tourney[id]'");
$thistourney=mysql_fetch_array($thistourney);
}

if($thistourney[id]){
show_tourney($tourney,$thistourney);
}else{
list_tourneys();
}

function list_tourneys(){
global $config;

$totaltour=mysql_query("SELECT COUNT(*) FROM tourneys where fend=1");
$totaltour=mysql_fetch_array($totaltour);
$totaltour="$totaltour[0]";

$tourneys=mysql_query("SELECT id,name,ladderon,size,cost,DATE_FORMAT(signupdate,'%M %d, %Y'),DATE_FORMAT(date,'%M %d, %Y'),DATE_FORMAT(finished,'%M %d, %Y'),prize,details FROM tourneys where fend=1 ORDER BY finished DESC");
while(list($id,$name,$ladderon,$size,$cost,$signupdate,$date,$finish,$prize,$details)=mysql_fetch_row($tourneys)){

$winnerid=mysql_query("SELECT winner FROM tourney_$size where tourneyid=$id");
while(list($twinner)=mysql_fetch_row($winnerid)){

$winnername=mysql_query("SELECT name FROM teams where id=$twinner");
while(list($twinnername)=mysql_fetch_row($winnername)){

$getladder=mysql_query("SELECT id,name FROM ladders WHERE active='1' AND id='$ladderon'");
$ladder=mysql_fetch_array($getladder);

$spotsleft=(mysql_num_rows(mysql_query("SELECT * FROM tourneyplayers WHERE tourneyid='$id'")));
if($spotsleft >= $size){
$spots="FULL";
}else{
$spots="$spotsleft/$size";
}

$out[body].="<br /><center>
<table bgcolor='#000000' cellspacing='1' cellpadding='1' width='90%'>
<tr bgcolor='$config[altcolora]'>
<td width=100%' background='$config[bg]'><b>$name - Completed: $finish - <a href='./oldtourney.php?tourney[id]=$id'>View Results</a></b></td></tr>
<tr bgcolor='$config[altcolora]'>
<td width=100%'><table width='100%' bgcolor='#000000' cellspacing='1' cellpadding='1'><tr bgcolor='$config[altcolora]'>
<td width='25%' align='left' background='$config[cellbg]'><b>Tournament Game</b></td>
<td width='25%' align='left' background='$config[cellbg]'><a href='./standings.php?ladder[id]=$ladder[id]'>$ladder[name]</a></td></tr>
<tr>
<td width='25%' align='left' background='$config[cellbg]'><b>Tournament Winner</b></td>
<td width='25%' align='left' background='$config[cellbg]'><a href='./stats.php?account=$twinner'>$twinnername</a></td>


</tr>
</table></center></td></tr></table>

";
}}}
if($totaltour == 0){
$out[body].="<br />
<center>
<table width='90%' border='0' cellspacing='1' cellpadding='1' bgcolor='#00000'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong>Tournament</strong>
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='100%' valign='center' align='left'><center>
<b>There are currently no tournaments.</b></center></td></tr>
</table>
</center><br /><br /><br /><br />";
}
$out[body].="<br /><br /><br /><br />";
include("$config[html]");
}

function show_tourney($tourney,$thistourney){
global $config,$out,$team,$thistourney,$binfo;

include("./includes/brackets.php");


$getladder = mysql_query("SELECT id,name FROM ladders WHERE id='$thistourney[ladderon]'");
$ladder = mysql_fetch_array($getladder);

$bracketinfo = mysql_query("SELECT * FROM tourney_".$thistourney['size']." WHERE tourneyid='$thistourney[id]'");
$binfo = mysql_fetch_array($bracketinfo);

$spotsleft=$thistourney[size]-(mysql_num_rows(mysql_query("SELECT * FROM tourneyplayers WHERE tourneyid='$thistourney[id]'")));

$ts=mysql_query("SELECT DATE_FORMAT(signupdate,'%M %d, %Y') as \"signupdate\" FROM tourneys WHERE id='$thistourney[id]'");
$ts=mysql_fetch_array($ts);

$td=mysql_query("SELECT DATE_FORMAT(date,'%M %d, %Y') as \"date\" FROM tourneys WHERE id='$thistourney[id]'");
$td=mysql_fetch_array($td);


$out[body].="
<center>

<table border='0' width='95%'><tr><td>
<table width='98%' border='0' cellspacing='1' cellpadding='2' bgcolor='#000000'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong>Tournament Details</strong>
</td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='40%' valign='center' align='left' background='$config[cellbg]'><b>Size: $thistourney[size]</b></td>
<td width='40%' valign='center' align='left' background='$config[cellbg]'><b>Spots Remaining: $spotsleft</b></td></tr>
<tr bgcolor='$config[altcolorb]'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2'><b>Details:</b> $thistourney[details]</td>
</tr>
</table>
</td></tr>
<tr><td align='right'><a href='./oldtourney.php'><<< Go Back to Tournament List</a></td></tr>
</table>
<br>
";
if($thistourney[size]==4){
bracket4();
}
elseif($thistourney[size]=={
bracket8();
}
elseif($thistourney[size]==16){
bracket16();
}
elseif($thistourney[size]==32){
bracket32();
}


include("$config[html]");

}

?>


Link to comment
Share on other sites

look up mysql "LIMIT" documentation. You'd be using 0,5 for your first 5... from there its pagination fun (headaches).

you'll need to dynamically change the limit to "5, 5" to "10, 5" to "15, 5" to .......... which can be done in several ways but usually is accomplished through a query string value so that you can use numbered links to switch through the pages.

Do read the basic-pagination link though from ober.... I just had already typed this up when he posted that

Link to comment
Share on other sites

i found another page that i had created for me that has it done, cant quite break down the code though.....

 

<?


include("./includes/incglobal.php");

if(!$page){
$page="1";
}
$letterlink="&ltr=$ltr";
$page=($page - 1);

$alphanum = array_merge(range('A','Z'));

$x=1;
foreach($alphanum AS $char){

$pipe = ($x == count($alphanum)) ? "" : " | ";

$link.= ($_GET['ltr'] == $char) ? $char . $pipe : "<a href=\"members.php?ltr=".$char."\">".$char."</a>" . $pipe;	
$x++; 
}

$ltr = $_GET['ltr'];

$out[body].="
<br />
<center>
<div style='background-color:$config[altcolora];width:90%;border: 1px solid rgb(0, 0, 0);'>
$link</div><br />
<table width='90%' border='0' cellspacing='1' cellpadding='1' bgcolor='#000000' cellpadding='1' cellspacing='1'>
<tr bgcolor='$config[altcolor]'>
<td width='100%' valign='center' background='$config[bg]' colspan='5'><b> Members List</b></td>
</tr><tr bgcolor='$config[altcolorb]'>
<td width='5%' valign='center' background='$config[bg2]' align='center'></td>
<td width='28%' valign='center' background='$config[bg2]' align='center'><b>Name</b></td>
<td width='15%' valign='center' background='$config[bg2]' align='center'><b>Contact</b></td>
<td width='22%' valign='center' background='$config[bg2]' align='center'><b>Points</b></td>
<td width='25%' valign='center' background='$config[bg2]' align='center'><b>Joined</b></td>
</tr>";
$select = "SELECT *,DATE_FORMAT(joined,'%M %d, %Y') as \"Joined\" FROM `members` WHERE `name` LIKE '".$ltr."%' ORDER BY name LIMIT $page,25";
$memb = mysql_query($select) or die(mysql_error());
while($mem = mysql_fetch_assoc($memb)){

if($config[altcolorx]==$config[altcolora]){
$config[altcolorx]="$config[altcolorb]";
}else{
$config[altcolorx]="$config[altcolora]";
}
if($config[cellbgx]==$config[cellbg]){$config[cellbgx]="$config[cellbg2]";}else{$config[cellbgx]="$config[cellbg]";}

$timeoutseconds = 300;
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
if($mem[lastactive] >= $timeout){
$online="<img src='./images/online.gif' border='0' alt='User is online now!' />";
}else{
$online="<img src='./images/offline.gif' border='0' alt='User is offline.' />";
}

if($mem[aim]){
$aimname="<a href='aim:goim?screenname=$mem[aim]&message=Hi'><img src='$config[scripturl]/images/aim.gif' border='0'></a>";
}else{
$aimname="";
}

$emailer="<a href='mailto:$mem[email]'><img src='$config[scripturl]/images/email.gif' border='0'></a>";

$out[body].="
<tr bgcolor='$config[altcolorx]'>
<td width='5%' valign='center' align='center' background='$config[cellbgx]'>$online</td>
<td width='28%' valign='center' align='left' background='$config[cellbgx]'><img src='./images/flags/{$mem[country]}_small.gif' border='0' /> 
<a href='./profile.php?account=$mem[id]'>$mem[name]</a></td>
<td width='15%' valign='center' align='center' background='$config[cellbgx]'>$aimname $emailer</td>
<td width='22%' valign='center' align='center' background='$config[cellbgx]'>$mem[points]</td>
<td width='25%' valign='center' align='center' background='$config[cellbgx]'>$mem[Joined]</td>
</tr>";
}

if(mysql_num_rows($memb) == 0){
$out[body].="
<tr bgcolor='$config[altcolora]'>
<td width='100%' colspan='5' valign='center' align='center' background='$config[cellbg]'>No Results</td>
</tr>";
}
$out[body].="</table>";

$pagenow=($page + 1);

$totalmem=mysql_query("SELECT COUNT(*) FROM members WHERE 'name' LIKE '".$ltr."%'");
$totalmem=mysql_fetch_array($totalmem);
$totalmem="$totalmem[0]";

$pages=1;
if($pagenow==1){
$skipranks.="[<a href='$config[scripturl]/members.php?page=1$letterlink'><b>$pages</b></a>] ";
}else{
$skipranks.="<a href='$config[scripturl]/members.php?page=1$letterlink'><b>$pages</b></a> ";
}

$arank=1;
$brank=25;

while($brank < $totalmem){
$arank=($arank + 25);
$brank=($brank + 25);
$pages++;

if($pagenow==$arank){
$skipranks.="[<a href='$config[scripturl]/members.php?page=$arank$letterlink'><b>$pages</b></a>] ";
}else{
$skipranks.="<a href='$config[scripturl]/members.php?page=$arank$letterlink'><b>$pages</b></a> ";
}
}
$out[body].="<br />$skipranks<br /><br /><table width='40%' border='0' cellspacing='1' cellpadding='1' bgcolor='#000000' cellpadding='1' cellspacing='1'>
<tr bgcolor='$config[altcolor]'>
<td width='100%' valign='center' background='$config[bg]' colspan='5'><b> Search Members</b></td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='5%' valign='center' align='center' background='$config[cellbg]'><form method='post' action='./search.php' style='margin-bottom: 0'>
<input type='text' name='search[string]' class='input' maxlength='30' style='vertical-align:middle;' value='Search Members' onClick=\"this.value=''\">
<input type='hidden' name='search[type]' value='mem'> 
<input type='submit' class='button' name='submit' value='Search'>
</form>
</div></td>
</tr></table><br /><br />";

include("$config[html]");

?>

Link to comment
Share on other sites

In your example given, the page builds an array of letters A-Z and then produces links for each letter.

The links are output in what I'm guessing looks like [iurl=#]A[/iurl] | [iurl=#]B[/iurl] | [iurl=#]C[/iurl] | . . .

When a user clicks one of these links, the letter is passed into the variable $_GET['ltr'] where it is used in the MySQL query. A similar tactic is used to paginate results, but not close enough to copy this code and make mods to it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.