Greetings.
I am attempting to write a function to query a database and return() an array containing the results. RIght now the function refuses to return() the array.
At this point, I wouldn't care if the array was a single joined variable, but I would like to avoid re-inventing the wheel if possible.
In going through the boards here, I see this working, or appear to be working. This leads me to believe I am missing something very basic. Is there anyone here who might be able to give me a few examples? The array size would vary from query to query, as you will se in the example code, each $query will be followed by a call to function getstuff($query). The function in question is at the bottom of the code. I have tessted that the function does indeed aquire the data requested, It just refuses to return() it.
Any suggestions?
2Hawks.
The Code:
$query="select * from relations where id=12";
getstuff($query);
echo ($results[0]); // Echo the result to verify results. The rest of the script requires this information.
exit; // This is here for testing. I don't like looking at the errors
// This is the coding mess I want to replace with function calls.
// a working version can be found at:
// http://www.clanbaker.com/family/fam_query.php
// Begin the retrieval of relationships and display the results as content.
echo "<table width=600 cellpadding=0 cellspacing=0 border=0><tr>";
echo "<td><Font size=+1><B>$results[4] $results[5] $results[6]</b></td>";
echo "<td></td><tr><TD class=\"gencell2\" align=left bgcolor=#DCCAA7>Mother:</td>";
echo "<TD class=\"gencell2\" align=right bgcolor=#DCCAA7>";
$query="select ID, 1stName, 2ndName, 3rdName from relations where ID=$results[2]"; // we are looking at Mom
if (!$link = @mysql_connect($db_host, $db_user, $db_pass)) {$DB_ERR="Error Connecting to Host!!"; DB_DED($DB_ERR);}
else { if (!@mysql_select_db($db_name, $link)) {$DB_ERR="Error Connecting to Database at Host!!"; DB_DED($DB_ERR);}
else { if(!$result = @mysql_query($query, $link)) {$DB_ERR="Error Accessing relations!!"; DB_DED($DB_ERR);}
$Mom = mysql_fetch_array($result);}}
if( $relations[2] == 0) {echo "Mother not in DataBase";}
else {echo "<a href=\"familytree.php?action=$relations[0]\"\>$Mom[1] $Mom[2] $Mom[3]</a\>";}
echo "</td></tr><tr><TD class=\"gencell1\" align=left>Father:</td><TD class=\"gencell1\" align=right>";
$query="select ID, 1stName, 2ndName, 3rdName from relations where ID=$relations[3]"; // we are looking at Dad
if (!$link = @mysql_connect($db_host, $db_user, $db_pass)) {$DB_ERR="Error Connecting to Host!!"; DB_DED($DB_ERR);}
else { if (!@mysql_select_db($db_name, $link)) {$DB_ERR="Error Connecting to Database at Host!!"; DB_DED($DB_ERR);}
else { if(!$result = @mysql_query($query, $link)) {$DB_ERR="Error Accessing relations!!"; DB_DED($DB_ERR);}
$Dad = mysql_fetch_array($result);}}
if( $relations[2] == 0) {echo "Father not in DataBase";}
else {echo "<a href=\"familytree.php?action=$relations[0]\"\>$Dad[1] $Dad[2] $Dad[3]</a\>";}
echo "</td></tr><tr><TD class=\"gencell2\" align=left bgcolor=#DCCAA7>Born:</td><TD class=\"gencell1\" align=right>";
function getstuff($query)
{
require("./connect.php");
if (!$link = @mysql_connect($db_host, $db_user, $db_pass)) {$DB_ERR="Error Connecting to Host!!"; DB_DED($DB_ERR);}
else { if (!@mysql_select_db($db_name, $link)) {$DB_ERR="Error Connecting to Database at Host!!"; DB_DED($DB_ERR);}
else { if(!$result = @mysql_query($query, $link)) {$DB_ERR="Error Accessing relations!!"; DB_DED($DB_ERR);}
$results = mysql_fetch_array($result);}}
return $results; // <--- Am I missing something? <-----------<<
}