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:
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($qr y, $this->database_lin k) or die ("Error: ".mysql_error() );
$returnArray = array();
$i = 0;
while ($row = mysql_fetch_arr ay($result, MYSQL_BOTH));
if($row)
$returnArray[$i++] = $row;
mysql_free_resu lt($result);
return $returnArray;
}
[/PHP]
I'm using the following code to access the function:
[PHP]
$parent_array = $db->query("SELEC T * FROM table WHERE parent='Y' AND username='$user name'");
[/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.
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($qr y, $this->database_lin k) or die ("Error: ".mysql_error() );
$returnArray = array();
$i = 0;
while ($row = mysql_fetch_arr ay($result, MYSQL_BOTH));
if($row)
$returnArray[$i++] = $row;
mysql_free_resu lt($result);
return $returnArray;
}
[/PHP]
I'm using the following code to access the function:
[PHP]
$parent_array = $db->query("SELEC T * FROM table WHERE parent='Y' AND username='$user name'");
[/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.
Comment