Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-02-2009, 01:20 PM while loop
Average Talker

Posts: 26
Trades: 0
Hi there, can someone help me adjust this while loop at all. I want to only display 20 posts at a time from the news table in my database

PHP Code:
<?php

$sql 
=mysql_query("SELECT * FROM news WHERE sentinfo = curdate() ORDER BY senttime DESC");



while(
$row mysql_fetch_array($sql))
{

   

echo 
"<td <strong>" $row['username'] . "</td>";
print 
": </strong>";
echo 
"&nbsp";
echo  
"<td>" $row['comment'] . "</td>" ;
print 
"<br>";
print 
"<i>posted at </i>";
echo 
"<td>" $row['senttime'] . "</td>";
print 
"<br>";
print 
"<br>";

}

?>
So i want to limit the loop to only ever display 20 posts...anyone adjust it to help with that?

thank alot
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-02-2009, 02:10 PM Re: while loop
Knight13's Avatar
Defies a Status

Posts: 10,289
Name: Knight13
Location: Cleveland, Ohio
Trades: 0
At the end of your query add LIMIT 20

PHP Code:

<?php

$sql 
mysql_query('SELECT * FROM news WHERE sentinfo = curdate() ORDER BY senttime DESC LIMIT 20');

while(
$row mysql_fetch_assoc($sql))
{
echo 
'<td><strong>'$row['username'] .':</strong></td>
<td>' 
$row['comment'] . '</td>
<br />
<em>posted at </em>
<td>' 
$row['senttime'] . '</td>
<br />
<br />'
;
}

?>
Also i fixed a few tags in your coding.

Last edited by Knight13; 12-02-2009 at 02:43 PM..
Knight13 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to while loop
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31197 seconds with 12 queries