TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   looping problem (http://www.talkphp.com/absolute-beginners/2730-looping-problem.html)

kororo203 04-29-2008 09:06 AM

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...

TlcAndres 04-29-2008 09:59 AM

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)

Village Idiot 04-29-2008 02:48 PM

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.


All times are GMT. The time now is 06:24 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0