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? Quote 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; } Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.