...

View Full Version : mysql_fetch_array in a function



FUN
09-18-2005, 02:25 AM
I'm stuck, i made a function that gets the news from the database, and it is supposed to get 4 last rows of the database, and then after i print it is suppose to output 4 last results, but it doesn't it ouputs only one...


function news(){
$newsdb="SELECT*FROM news order by id";
$getnews=mysql_query($newsdb) or die(mysql_error());
while($r=mysql_fetch_array($getnews)){
$id=$r[id];
$title=$r[title];
$body=$r[body];
$writter=$r[username];
$time=$r[time];
$newsboard="$title <br /> $body <br />$writter <br /> \n $time <br /> \n<a href=\"$self?nid=$id\">comments</a><br />";
}
return $newsboard;
}




and they i print it


<?php
print news();
?>


Can u tell me where is the mistake...

It seems that it returns the first thing that it gets in $newsboard var... but how to make so it takes all the rows ???

firepages
09-18-2005, 03:28 AM
$newsboard .= "etc, note the '.' (dot)";

FUN
09-18-2005, 03:32 AM
wow, thanks firepages, your help was brilliant and simple!
i've tried everything but i had to put only 1 dot, brilliant, lol,

Me stupid :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum