br3nn4n Posted November 25, 2007 Share Posted November 25, 2007 This is probably really really simple, but I can't get it to work on my end...haha. So I have this mysql database. It works great, the stuff outputs how I want. But I'm making a news website and I need to change the articles each month. I'm putting all the articles into one database, then into each page as tables (ie: news, opinion, sports, etc.), then the articles each have their own row. On the homepage here it outputs all 5 articles from the news table, but I only want it to output result numbers (blah) through (whatever). Here's the code used on the page to output the 5: <? $query1 = mysql_query("SELECT * FROM news"); while ($result1 = mysql_fetch_array($query1)) { for ($i = 0; $i < mysql_num_rows($query1) { echo "<a href=\"index.php?page=news&article=$result1[id]\"><b>$result1[title]</b></a>"; echo "<br /><i>$result1[date]</i>"; echo "<br />By <i>$result1[name]</i>"; echo "<br />$result1[desc]"; echo "<br><br>"; break; $i++; } } ?> I'm only recently getting into dynamic coding (ie: php) and these forums have been a lot of help with other things, so thanks in advance! Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 25, 2007 Share Posted November 25, 2007 Your not real clear on what your trying to do. It sounds like you may be looking for "pagination", so try googling that. Also, the for loop inside of your while loop doesn't look like it's needed. Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 25, 2007 Author Share Posted November 25, 2007 Okay then To clarify, mysql_num_rows outputs 5 rows. Although, from that 5 I only want to show results number 3 through 5. That make more sense? Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 25, 2007 Share Posted November 25, 2007 then create a counter inside your loop.. Eg++$ctr.. the after you reach your desired number do some stuff ... Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 26, 2007 Author Share Posted November 26, 2007 Oh okay, so have it count the number of outputted (sp?) results and stop at a whatever number I want? I'm really just figuring this stuff out as I go so any clarification would be great Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 26, 2007 Share Posted November 26, 2007 loophere{ ++$count; if ($count!=3){ continue; } else{ // do your stuff here } } syntax... Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 26, 2007 Author Share Posted November 26, 2007 Ah, gotcha..now, any way to start the visible output from, say, result 3? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 26, 2007 Share Posted November 26, 2007 Just use LIMIT in your query. If you wanted ONLY results 3-5 you would do this: <?php $query1 = mysql_query("SELECT * FROM news LIMIT 3,5"); ?> Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 26, 2007 Author Share Posted November 26, 2007 Sweet, perfect! Thanks so much! 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.