I have categories up to n levels and my db is like: Category: catid,catname,parent parent = n //where n is the value of parent category function myFun($id) { $res = mysql_query("select * from categories where parent=".$id."") or die("Here is error"); while($row = mysql_fetch_array($res)) { myFun($row["catid"]) } } myFun2(2) PHP: but this is not workin any help? thank you
Firstly how do you know it is not working? There is no action to be performed there so we can detect if it is working or not. Secondly, I guess you'd better use "if" instead of "while"
try this instead function myFun($id) { $res = mysql_query("select * from categories where parent='".$id."'") or die("Here is error"); while($row = mysql_fetch_array($res)) { myFun($row["catid"]) } } myFun2(2) PHP: on myFun2(2) the parent='2' just added two ' at the $res
Integers don't need to be enclosed in quotes. Maybe you want to have a look at this though. http://www.codeassembly.com/How-to-...pandable-categories-using-php-and-javascript/
$res = mysql_query("select * from categories where parent=$id") or die("Here is error"); use it, i did not check it, but it should work because you used (") double quote, so you can use variable within ("). thanks
It doesn't matter how PHP treats quoted numbers because in this instance the quoted numbers are in the MySQL query... not in PHP. In PHP you shouldn't ever quote numbers, in MySQL you shouldn't EVER quote numbers.
Your function never returns a value and does not output things so you can never tell if it does what it's supposed to do. But anyway I thing the initial call : ... myFun2(2) ... Code (markup): should be: ... myFun(2); ... Code (markup):