Jump to content

[SOLVED] MySQL query from within a function ?


zoonose

Recommended Posts

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);

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.