Jump to content

Returning values within a loop?


livewirerules

Recommended Posts

how do i return a value from a loop within a function?

 

function deprecated()
{
$sql="select * from table where id=1";
$result=mysql_query($sql) or die(mysql_error());

while ($row=mysql_fetch_array($result)) {

	$date=$row['date'];
               $cat=$row['cat'];


}
}

 

i want to return both $date and $cat.... How do i do it?

Link to comment
https://forums.phpfreaks.com/topic/203604-returning-values-within-a-loop/
Share on other sites

The best you can do is return an array.

 

function deprecated()
{
  $sql="select * from table where id=1";
  $result=mysql_query($sql) or die(mysql_error());
  $return = array();
  while ($row=mysql_fetch_array($result)) {
    $return[] = $row;
  }
  return $return;
}

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.