Well, just so you know, mysql_query returns a result identifier on a successful query - basically some sort of link connection thingy with the database.
So your choice of variable names in your code are prolly not the best. Try this:
$result =mysql_query($sql);
if($result)
$row_count=mysql_num_rows($result);
else
return false;
Notice how I check to see if mysql_query returned a valid result before using mysql_num_rows. If you don't mysql_num_rows will through an error if the result is invalid.
Anyway, onto your question. Try using tables. Maybe something like this:
function write_sub_category($id){
$sql="select rel.kat_id_1,kat.name
from categories as kat
inner join kat_rel as rel
on kat.id=rel.kat_id_1
where kat_id_2=".$id;
$result=mysql_query($sql);
if($result)
$row_count=mysql_num_rows($result);
else
return;
if($row_count>0){
echo "<table cellspacing=0 cellpadding=0 border=0><tr><td style='padding-left:15px;'>";
while($row=mysql_fetch_array($query)){
$tmpid=$row["kat_id_1"];
echo "»".$row["name"];
write_sub_category($tmpid);
}
echo "</td></tr></table>";
}
}
something like that anyway... Just depends what you want to do. Maybe the table needs to be printed in each iteration of the while loop. I can't really tell, as I'm not sure what you're doing. You'll know though. Do you really need those >> at the start? If you do, instead of
if($result)
$row_count=mysql_num_rows($result);
else
return;
do
if($result)
$row_count=mysql_num_rows($result);
else
">>";
and then just print it out when the function returns. you follow?
cya man.
-Adam 🙂