dezkit Posted July 13, 2008 Share Posted July 13, 2008 i wanna do it so that if there is more than 10 entries in the database, there will be a "2" on the bottom of the page to show like there is another page of entries. for example there are 5 entries in the database, and it doesnt show anything on the bottom, if there are more than 10, say 11, then it will show "2" at the bottom and it will show the entry Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 It's called pagination. Google it and you should get plenty of tutorials regarding it. Here are some links: http://www.tutorialized.com/tutorial/Pagination-with-PHP/6925 http://www.sitepoint.com/article/perfect-php-pagination http://www.pixel2life.com/tutorials/count/60828/simple_pagination_using_php/ http://www.pixel2life.com/tutorials/count/53905/learn_about_pagination_with_php_nice_tutorial_on_creating_paging/ Good luck. Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 gahh thanks<3 Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 oh wow, this pagination is screwing me up. can somebody please please please form a pagination out of this please. <h2 class="main"><span>Matches</span></h2> <div class="cbox matches"> <div> <? $q = mysql_query("SELECT * FROM `matches` ORDER BY id DESC"); $matches = mysql_num_rows($q); if($matches) { ?> <? echo " <p style='font-size: 14px;'> <b>$clanname</b> <br />$wins-$losses-$ties </p>"; ?> <table cellspacing="0" cellpadding="2"> <? $i = 0; while($r = mysql_fetch_array($q)) { $i += 1; $winner = split("-",$r['score']); if($winner[0] > $winner[1]) { $status = "<td class=\"win\">Won</td>"; } else if($winner[0] < $winner[1]) { $status = "<td class=\"loss\">Loss</td>"; } else { $status = "<td class=\"tie\">Tie</td>"; } ?> <tr class="row<?=($i&1)?>"> <td>Extinguish <font style="font-size:8pt; font-weight:bold; color: #888888;">vs</font> <?=$r['team2']?></td> <td class="score"><?=$r['score']?></td> <?=$status?> </tr> <?if($r['info'] != "") { ?> <tr class="row<?=($i&1)?>"> <td colspan="3" class="comments"><i> HLTV Demo: <a href="demos/<?=$r['info']?>">download</a> </i></td> </tr> <? } } ?></table><? } else { echo "We haven't played any matches yet!"; } ?> </div> <center> <font size="-1" color=white> THIS IS WHERE THE 1 2 3 4 5 ETC HAS TO BE </font><br> </center> </div> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 Very messy code, if you don't mind me saying. <h2 class="main"><span>Matches</span></h2> <div class="cbox matches"> <div> <?php //HOW MAN MATCHES PER PAGE? $matchesPerPage = 10; //NOW WE GET THE PAGE THEY ARE VIEWING if(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; } $totalMatches = mysql_num_rows(mysql_query("SELECT * FROM `matches`")); $totalPages = ceil($totalMatches/$matchesPerPage); if($page > $totalPages){ //They are trying to view a page out of the range $page = $totalPages; } //This gets the number where we start from when limiting in our MySQL query $from = ($matchesPerPage * $page) - $matchesPerPage; $q = mysql_query("SELECT * FROM `matches` ORDER BY id DESC LIMIT {$from}, {$matchesPerPage}"); $matches = mysql_num_rows($q); if($matches > 0){ echo "<p style='font-size: 14px;'><b>{$clanname}</b> <br />{$wins}-{$losses}-{$ties}</p>"; ?> <table cellspacing="0" cellpadding="2"> <? $i = 0; while($r = mysql_fetch_array($q)) { $i += 1; $winner = split("-",$r['score']); if($winner[0] > $winner[1]) { $status = "<td class=\"win\">Won</td>"; } else if($winner[0] < $winner[1]) { $status = "<td class=\"loss\">Loss</td>"; } else { $status = "<td class=\"tie\">Tie</td>"; } ?> <tr class="row<?=($i&1)?>"> <td>Extinguish <font style="font-size:8pt; font-weight:bold; color: #888888;">vs</font> <?=$r['team2']?></td> <td class="score"><?=$r['score']?></td> <?=$status?> </tr> <?if($r['info'] != "") { ?> <tr class="row<?=($i&1)?>"> <td colspan="3" class="comments"><i> HLTV Demo: <a href="demos/<?=$r['info']?>">download</a> </i></td> </tr> <? } } ?></table><? } else { echo "We haven't played any matches yet!"; } ?> </div> <center> <font size="-1" color=white> <?php for($p = 1; $p < $totalPages; $p++){ if($p == $page){ echo "<b>{$p}</b> "; }else{ echo "<a href='yourpagelink.php?page={$p}'>{$p}</a> "; } } ?> </font><br> </center> </div> Hopefully I didn't miss anything. Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 OMG! thanks a whole bunch! but there is one itsy bitsy problem.. there are 4 entries i put 1 match per page it shows 3 pages. thanks! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 Heh, change this line: for($p = 1; $p < $totalPages; $p++){ To this: for($p = 1; $p <= $totalPages; $p++){ My bad. Quote Link to comment Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 heh! thanks soooooo sooooo sooo soooo much! topic solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.