Been trying for hours, I need to make my results come out paginated as they are loading quite large images. I need a limit of 16 items per page. <?php //GET ID FROM URL if(isset($_GET['id'])){ $id =$_GET['id']; //Connect to db mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); //Search query $result = mysql_query("SELECT * FROM cat_objects WHERE id = '$id'"); //Make sure there's rows if(mysql_num_rows($result)!=0) { while($row = mysql_fetch_array($result)) { $title = $row[title]; $url = $row[url]; }} else { echo "There is no catgegory here!"; }} include"../includes/head.php";?> <div style="float:left;width:30%;margin-right:-200px;border:1px solid #747474;min-height:300px;">CONTENT BOX/AD BOX/FEATURED MAGAZINES BOX<br></div> <?php //Get publication issues to generate images and category titles $resultc = mysql_query("SELECT * FROM publication_issue WHERE cat = '$id'"); ?> <div style="float:right;width:57%;margin-right:100px;"><h2>Latest <?php echo "$title";?> Publications</h2></div> <div style="border-bottom:4px solid #747474;width:57%;float:right;margin-top:-30px;margin-right:100px;"> </div> <div style="width:57%;margin-left:32px;float:right;margin-right:100px;"> <div class="otherpubcontainer"> <? while($rowc = mysql_fetch_array($resultc)) { $pubid = $rowc[publication_id]; //Get generic publication $resultb = mysql_query("SELECT * FROM publication WHERE id = '$pubid' ORDER BY id ASC LIMIT 16"); while($rowb = mysql_fetch_array($resultb)) { $pubtitle = $rowb[title]; $rowimg = $rowc[img]; } echo "<div class=\"otherpub1\"><img src=\"images/uploads/publications/image/big/$rowimg\" title=\"Read $pubtitle Online\" height=\"190px\"></div>"; } ?> </div> <!-- THESE ARE THE BUTTONS I NEED TO IMPLEMENT AS NEXT/PREVIOUS PAGE --> <div style="clear:both;"></div><br /><div style="width:650px;"><div style="float:left;width:40%;background:beige;border:1px solid silver;-moz-border-radius: 15px;border-radius: 15px;padding:5px;text-align:center;">Previous</div><div style="float:right;margin-right:30px;width:40%;background:beige;border:1px solid silver;-moz-border-radius: 15px;border-radius: 15px;padding:5px;text-align:center;">Next</div></div></div> </div> </div> </div> <?php include"../includes/footer.php";?> PHP: What is the best way to go about paginating the results without making utterly messy URLs?
Here's a quick example: <?php $itemsPerPage = 16; mysql_connect("", "", ""); mysql_select_db(""); $currentPageNumber = (int) $_GET['page']; if(empty($currentPageNumber)) $currentPageNumber = 1; $mpnQuery = "SELECT count(id) FROM example"; $result = mysql_query($mpnQuery) or die(mysql_error()); $data = mysql_fetch_array($result); $maxPageNumber = ceil($data[0]/$itemsPerPage); $start = ($currentPageNumber - 1) * $itemsPerPage; $query = "SELECT * FROM example LIMIT $start, $itemsPerPage"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row["example"]; echo '<br>'; } if($currentPageNumber==1){ echo 'Previous'; } else{ echo '<a href="?page=' .($currentPageNumber - 1). '">Previous</a>'; } echo ' - '; if($currentPageNumber==$maxPageNumber){ echo 'Next'; } else{ echo '<a href="?page=' .($currentPageNumber + 1). '">Next</a>'; } mysql_close(); ?> PHP: Also, are you aware of that your script is SQL injection vulnerable?
I know I should escape and close, I'm writing my scripts before I secure them. I've also just found out that MD5 is insecure so I decided to finish writing all the scripts then go and add a solid layer of security on them. Thanks.
I have an awful habit of writing my styles on the actual page BEFORE I put it all into a stylesheet. I know, ballache but its the way I work. 1. Design & Style on page 2. Convert style on page to css file 3. Write scripts and style on page 4. Convert script style to css file One day, I'll learn to stop making too much work for myself.