Hi,
i would like to show you this mystic result
PHP Code:
function delete()
{
$id = $this->input->post('id');
$this->deletecategory($id);
}
function deletecategory($cat_id)
{
$query = "SELECT id,cop from products WHERE pid='$cat_id'";
echo $query."\n";
$q = mysql_query($query);
while($row = mysql_fetch_assoc($q))
{
if($row['cop'])//if category
{
$this->deletecategory($row['id']); //loop to the lower level
}
}
$qy = "DELETE FROM products WHERE id='".$row['id']."';";
echo $qy."\n";
// $q = mysql_query($qy); //remove this entry
}
i am getting this as result...
Code:
SELECT id,cop from products WHERE pid='8'
SELECT id,cop from products WHERE pid='9'
DELETE FROM products WHERE id='';
SELECT id,cop from products WHERE pid='10'
DELETE FROM products WHERE id='';
DELETE FROM products WHERE id='';
the variable row[id'] is going out out scope after this line
$this->deletecategory($row['id']); //loop to the lower level
Why?
I have used recursion for files and folders and it works well but i did not
use that to this process. what am i missing here?
Bookmarks