livewirerules Posted June 2, 2010 Share Posted June 2, 2010 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 More sharing options...
trq Posted June 2, 2010 Share Posted June 2, 2010 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; } Link to comment https://forums.phpfreaks.com/topic/203604-returning-values-within-a-loop/#findComment-1066516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.