unsider Posted July 19, 2008 Share Posted July 19, 2008 PHP Freaks Forums > PHP > PHP Help > Start new topic Can someone explain the logic behind this method? What it's called? Point me towards a tutorial? Thanks. Quote Link to comment Share on other sites More sharing options...
marcus Posted July 19, 2008 Share Posted July 19, 2008 main_cats sub_cats topics --------- ---------- -------- id ---| id ---| id name +--- mid +--- sid name name You have your main category being PHP, your sub-category PHP Help and your topic Forum Nav-Bar? <?php $topic_id = mysql_real_escape_string($_GET['id']); // example $sql = "SELECT * FROM `topics` WHERE `id`='".$topic_id."'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); $sql2 = "SELECT mid,name FROM `sub_cats` WHERE `id`='".$row['sid']."'"; $res2 = mysql_query($sql2) or die(mysql_error()); $row2 = mysql_fetch_assoc($res2); $sql3 = "SELECT name FROM `main_cats` WHERE `id`='".$row2['mid']."'"; $res3 = mysql_query($sql3) or die(mysql_error()); $row3 = mysql_fetch_assoc($res3); echo $row3['name'] . " > " . $row2['name'] . " > " . $row['name']; ?> I'm sure you can easily put that into one query, I don't deal with joins :x Quote Link to comment Share on other sites More sharing options...
unsider Posted July 19, 2008 Author Share Posted July 19, 2008 Thanks, makes perfect sense, confirms a few ideas I had, and completes my thought. And the single query won't be a problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.