Jump to content

php function with loop query


desithugg

Recommended Posts

<?
function get_shoutz($user,$start,$limit)
{
if($start=="") { $start="0"; }
if($limit=="") { $limit="5"; }
$query = "SELECT * FROM shoutz where owner='$user' limit $start,$limit"; 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){$count++;
$poster = $row["poster"];
$dst = $row["date"];
$shout = $row["shout"];
$whole_thing "<b>".$poster."</b><br>".$dst."<br>"."<div class='shout'>".$shout."</div>";
}
}
get_shoutz("1","","");
?>

Umm what it does is fetches rows from a table called shoutz depending on the start and limit variables.

So in this case it would use the defauly 0 for start and 5 for limit.

anyways

the rows are being fetched in a loop what I want to do is combine all the 5 rows fetched in to one variable like $shotbox and than use return $shoutbox; at the end of the function so where ever i put get_shouts("1","",""); it will show the whole thing.

 

Sorry if i'm confusing. not sure how to say it.

 

Link to comment
https://forums.phpfreaks.com/topic/49038-php-function-with-loop-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.