PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Now this calls up a class which uses a LIMIT function internally. So the code works great and is retrieving the results I want except I want to skip the first row it returns. Now I know this is generally a weird request but I want to skip the first row and start on the second. So instead of starting the while loop on row
I want it to start on row [1]. I hope I explained this clearly enough if not just let me know. Thanks for the help!
<!-- THIS IS WHERE THE MAIN SUB CONTENT QUERY STARTS -->
<?php
//Include the PS_Pagination class
include('ps_pagination.php');
//Connect to mysql db
$conn = mysql_connect('localhost', 'username', 'password');
mysql_select_db('test_db',$conn);
//$sql = 'SELECT * FROM articles WHERE article_type ="News" AND idarticles="70" ORDER BY date_uploaded DESC';
//To sort it by certain article type
$sql = 'SELECT * FROM articles ORDER BY date_uploaded DESC';
//Create a PS_Pagination object
$pager = new PS_Pagination($conn, $sql, 8, 10, 'param1=valu1¶m2=value2');
//The paginate() function returns a mysql
//result set for the current page
$rs = $pager->paginate();
//Loop through the result set
//DEFAULT SKIPS FIRST RECENT BECAUSE IT WILL DUPLICATE
while($row = mysql_fetch_assoc($rs)) {
echo "
<div id=\"left_lower_content\">
<div id=\"left_lower_content_top\"><p class=\"left_lower_content_top_class\">{$row['article_type']}</p></div>
<div id=\"left_lower_content_image\"><a href=\"view_article.php?id={$row['idarticles']}&lightbox[width]=950&lightbox[height]=700&lightbox[modal]=true\" class=\"lightbox\"><img name=\"left_lower_content_image\" src=\"{$row['article_big_image']}\" width=\"300\" height=\"170\" alt=\"\" style=\"background-color: #999999\" /></a></div>
<div id=\"left_lower_content_main_text\">
<p class=\"left_lower_content_title lightbox\"><a href=\"view_article.php?id={$row['idarticles']}lightbox[width]=1000&lightbox[height]=200&lightbox[modal]=true\">{$row['article_title']}</a></p>
<p class=\"left_lower_content_text\">{$row['small_description']}</p>
</div>
<a href=\"view_article.php?id={$row['idarticles']}lightbox[width]=1000&lightbox[height]=200&lightbox[modal]=true\"><img src=\"images/full_article.jpg\" width=\"86\" height=\"15\" alt=\"full_article\" class=\"full_article_sub_article lightbox\" /></a>
<div id=\"left_lower_content_bottom_div\"><p class=\"left_lower_content_bottom\">Posted by: Felix Henriques | {$row['views']} Views | Posted on: {$row['date_uploaded']} | <a href=\"#\">{$row['comments']} Comments</a></p></div>
<div id=\"left_lower_spacer\"></div>
</div>
";
; }
//Display the navigation
echo'<div id="pagination">';
echo'<p class="pagination">';
echo $pager->renderFullNav();
echo'</p>';
echo'</div>';
?>
Thanks for the response,
the only thing is that it keeps skipping the first row. I was looking for it to skip just the first entry and continue on in the loop without skipping the first result. What happens is that when I include that code it skips the first result each time and it actually ends up only showing 7 results when I have it set up to show 8. So any other solutions? Let me know if you want to see the Pagination PHP script as well.
Sorry about the confusion. I'll try and explain a little more clearly. So in my database there is a total of 14 rows of data. I want to skip just the first retrieved row out of the 14. Now in my pagination script I have it showing 8 records per page. What happens when I used your suggestion is that it would skip the first row but it would only show 7 records per page. Also on the second page the first row was skipped as well. So thats the ninth record of the 14. So I just want the first record out of the 14 skipped and then have it continue on retrieving the records without skipping another record. I hope this helps Chris and thanks for all the help you have given me!
It sounds like you are trying to show one featured article on its own and then list the other 13 articles. Do you know the ID of the featured article? If so you could change your SQL to something like:
SELECT * FROM articles WHERE id != $id ORDER BY date_uploaded DESC
That will show all the articles except the one you want to skip (you need to set $id to its ID).
Chris this is the right idea but the only problem is that when I upload a new article that specific article will Change that I want skipped. I can put in the Id and it will work but if I uploaded another article then I would have to go into the code and change the Id. Is there a way where I can have it skip the first Id automatically. You have the right idea though and you are right with knowing that I don't want the first result to show. Thanks again and I would use limit but the pagination class is already using a limit clause so that's out of the option.
I would probably add another field to the table called 'featured'. Then instead of selecting on 'WHERE id != $id' select 'WHERE featured!= 1'. When you add records, first do 'UPDATE articles SET featured=0' to clear the current featured record. Then add the new article with featured set to 1.