FridayRain Posted September 11, 2007 Share Posted September 11, 2007 I've tried Googling but I must not know the proper words to include. I'm thinking this is simple math. Something like adding 1 to a variable such as $id. My main page will display blog entries, but my right column display the titles of the four most recent pieces from each category, including the blog. Since this column is on every page, there's no need to display blog entries that are already on the front page, so I'd like the query to skip the first three entries and start with the fifth most recent. This is the code for the right column pulling blog entry titles: <?php require("db/config.php"); require("db/opendb.php"); $query = "SELECT * FROM blog ORDER BY date DESC LIMIT 4"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $titlesb[] = "<span>+ </span><a href=\"blogs.php?piece={$row[id]}\">{$row[title]}</a>"; } require("db/closedb.php"); echo implode('<br />', $titlesb); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/ Share on other sites More sharing options...
Barand Posted September 11, 2007 Share Posted September 11, 2007 To get the remaining records use "LIMIT 4, 99999999" Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346447 Share on other sites More sharing options...
FridayRain Posted September 11, 2007 Author Share Posted September 11, 2007 ...and then what? Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346463 Share on other sites More sharing options...
liebs19 Posted September 11, 2007 Share Posted September 11, 2007 The LIMIT 4, 99999999 will start at the 4th record and select everything else. You won't need to do anything else in your code to skip over them. Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346475 Share on other sites More sharing options...
FridayRain Posted September 12, 2007 Author Share Posted September 12, 2007 Hmm. I tried it and all it displayed was the title of the first entry. Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346481 Share on other sites More sharing options...
liebs19 Posted September 12, 2007 Share Posted September 12, 2007 Have you tried echoing out the <span> tags inside the while loop as they are generated instead of storing them in an array and doing an implode? I'm not familiar with the implode command so it might work fine but it could be worth a try. Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346483 Share on other sites More sharing options...
FridayRain Posted September 12, 2007 Author Share Posted September 12, 2007 Didn't change anything. Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346516 Share on other sites More sharing options...
FridayRain Posted September 12, 2007 Author Share Posted September 12, 2007 Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346546 Share on other sites More sharing options...
pocobueno1388 Posted September 12, 2007 Share Posted September 12, 2007 Change: $query = "SELECT * FROM blog ORDER BY date DESC LIMIT 4"; To: $query = "SELECT * FROM blog ORDER BY date DESC LIMIT 4, 99999999"; Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346552 Share on other sites More sharing options...
FridayRain Posted September 12, 2007 Author Share Posted September 12, 2007 Wow, I'm a dufas. Both of your suggestions (they're the same) actually worked. I only had five test entries in the database. I get two entries to display when I set the limit to 3. Eesh. Thanks, guys. Quote Link to comment https://forums.phpfreaks.com/topic/68924-solved-fetch-array-but-skip-the-first-few-results/#findComment-346563 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.