TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-29-2008, 09:06 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default looping problem


$r=0;
$sql = "SELECT * FROM news ORDER BY id DESC";
$result = mysql_query($sql);
while($rows = mysql_fetch_array($result) || $r!=3 )
{ echo $r.'<br/>';
echo $rows['datenum']; echo'<br/>';
$r = $r+1;
}


ths code make my browser er.. how do i say it... just BANG! hahaha
i think my codes are right but why doe the lopp does not stop i already had put a condition for the loop tp stop yet i just wont..

thanx for the help... peace...
kororo203 is offline  
Reply With Quote
Old 04-29-2008, 09:59 AM   #2 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

PHP Code:

$r 
0;
$sql "SELECT * FROM news ORDER BY id DESC";
$result mysql_query($sql);
while(
$rows mysql_fetch_array($result) && $r <= 3)

    echo 
$r.'<br/>';
    echo 
$rows['datenum']; echo'<br/>';
    ++
$r;

This is probably something along the lines that you want, it'll loop while theres rows to fetch and r is less then or equal to three when one condition is met it'll stop.

(Doing this reminded me on my dependance on a database wrapper...I haven't actually used mysql_fetch_array since php4 I think)
__________________
"What everyone seems to forget is that while knowledge certainly is something - it's the implementation of knowledge that brings power" - Andres Galindo.
TlcAndres is offline  
Reply With Quote
Old 04-29-2008, 02:48 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Could you please try to use better English next time? I find it hard to put time into someone who does not take their problem seriously enough to use English.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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


All times are GMT. The time now is 10:16 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design