zoonose Posted October 8, 2008 Share Posted October 8, 2008 Hi, I am having trouble with the following code. Any help is appreciated!! Problem: I have a MySQL query that generates a multi-dimensional array. However, when I place this within a function I get no output? It is very strange and I think I must be missing something very basic! This code works well and give me what I want:: foreach ($unique_events as $ID){ $palm_details[$ID] = array(); $sql = "SELECT * FROM `events` WHERE e_family = '$ID'"; $result = mysql_query($sql,$con) or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ array_push($palm_details[$ID],$row); } } print_r($palm_details); While this does not give me anything!?! function GetEvents ($unique_events,$con){ foreach ($unique_events as $ID){ $palm_details[$ID] = array(); $sql = "SELECT * FROM `events` WHERE e_family = '$ID'"; $result = mysql_query($sql,$con) or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ array_push($palm_details[$ID],$row); } } } $details = GetEvents($unique_events,$con); print_r($details); Link to comment https://forums.phpfreaks.com/topic/127511-solved-mysql-query-from-within-a-function/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2008 Share Posted October 8, 2008 Functions must have a return statement that returns the value (array) to the calling program. Link to comment https://forums.phpfreaks.com/topic/127511-solved-mysql-query-from-within-a-function/#findComment-659723 Share on other sites More sharing options...
zoonose Posted October 8, 2008 Author Share Posted October 8, 2008 Yup. I am totally self-taught and this was indeed a basic error. Thank you!!! Link to comment https://forums.phpfreaks.com/topic/127511-solved-mysql-query-from-within-a-function/#findComment-659735 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.