impactdesign Posted February 16, 2008 Share Posted February 16, 2008 I am new to php programming and I really need help getting a page to paginate. I have tried a bunch of codes found online, yet I can not get to merge with my current code. Here is the core of my code without pagination function. Can someone help me? Pleeeeeeeeeeeease???? <?php include("admin/includes/config.inc.php"); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY year DESC, month DESC, day DESC"; $result=mysql_query($sql); $num_rows = mysql_num_rows($result); ?> <style type="text/css"> <!-- .smbold {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 11px; } .smmainit { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; font-size: 11px; font-style: italic; } .smmain { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; font-size: 11px; } .link {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 11px; } --> </style> <table width="100%" border="0" cellspacing="3" cellpadding="3"> <tr> <td width="105" align="center"><span class="smbold">Date</span></td> <td width="264" align="center"><span class="smbold">Title</span></td> <td width="81" align="center"><span class="smbold">mp3</span></td> <td width="81" align="center" class="smbold"><div align="center">Download</div></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td valign="top"><div align="center" class="smmain"> <? echo $rows['month']; ?>/<? echo $rows['day']; ?>/<? echo $rows['year']; ?></span></td> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="smbold"><? echo $rows['title']; ?></span></span></td> </tr> <tr> <td class="smmainit"><? echo $rows['scripture']; ?></span></td> </tr> <tr> <td class="smmainit"><? echo $rows['ser_series']; ?></td> </tr> <tr> <td class="smmain"><? echo $rows['speaker']; ?></td> </tr> </table></td> <td align="center" valign="top"><a href="mp3/<? echo $rows['file']; ?>" class="link">Listen</a></td> <td align="center" valign="top"><div align="center"><a href="download.php?<? echo $rows['file']; ?>" class="link">Download</a></div></td> </tr> <?php } ?> </table> <?php mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 16, 2008 Share Posted February 16, 2008 admin were the tutoral for pag on here gon please server down why example needs tweeking but the idear there mate........ <?php $connection = @mysql_connect('localhost', '*****', '*****'); if (!$connection) { echo '<p>Unable to make database connection.</p>'; exit(); } if (!@mysql_select_db(' ')) { exit('<p>Unable to locate database.</p>'); } $limit = 10; $query_count = "SELECT count(*) FROM companyid_uks49179 WHERE town='Bury St. Edmunds' AND category='sleep' AND priority='0'"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT company FROM companyid_uks49179 WHERE town='Bury St. Edmunds' AND category='sleep' AND priority='0' LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $bgcolor = "#E0E0E0"; // light gray echo("<table>"); while($row = mysql_fetch_array($result)){ echo $row['company']."<br />"; } echo("</table>"); if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF?page=$pageprev\">PREV".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a"); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a"); } } if(($totalrows - ($limit * $page))){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</ a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> Quote Link to comment Share on other sites More sharing options...
impactdesign Posted February 17, 2008 Author Share Posted February 17, 2008 Thanks I will try that... 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.