Been using PHP for a little while now but have never really looked into using functions and such thinking I didn't really need them (coupled with me be lazy). I've started a new project and have decided to get a handle on them and this tutorial:
http://bytes.com/forum/thread632487.html
Has helped me quite a lot, I've made some modifications and it for the most part everything seems to be working however this one problem popping up is doing my head in I just can't seem to figure it out. I'm attempting to use the following function:
[PHP]
function query($qry)
{
if(!isset($this->database_link)) $this->connect();
$result = mysql_query($qry, $this->database_link) or die ("Error: ".mysql_error());
$returnArray = array();
$i = 0;
while ($row = mysql_fetch_array($result, MYSQL_BOTH));
if($row)
$returnArray[$i++] = $row;
mysql_free_result($result);
return $returnArray;
}
[/PHP]
I'm using the following code to access the function:
[PHP]
$parent_array = $db->query("SELECT * FROM table WHERE parent='Y' AND username='$username'");
[/PHP]
and I've tried echoing some results using the following:
[PHP]
echo $parent_array[1];
echo $parent_array['title'];
[/PHP]
But it is just showing up blank, probably somthing simple I'm missing but I've looked over that article many times and tried searching around but I'm coming up with nothing. I've narrowed down the problem as much as I can, I've tested other functions contained within the same file and they work fine, I've also tested the same query not using the function and arrays and it is also working.
Cheers for any help guys.