essjay_d12 Posted November 22, 2006 Share Posted November 22, 2006 I have the following db[table][tr][td]c_id[/td][td]name[/td][td]p_id[/td][/tr][tr][td]1[/td][td]News[/td][td]0[/td][/tr][tr][td]2[/td][td]Sport[/td][td]0[/td][/tr][tr][td]3[/td][td]Headlines[/td][td]1[/td][/tr][tr][td]6[/td][td]Last Week[/td][td]1[/td][/tr][tr][td]4[/td][td]Football[/td][td]2[/td][/tr][tr][td]5[/td][td]Nintendo Wii Sells Out!![/td][td]3[/td][/tr][/table]I get this to echo only the names with a parental id (p_id) of value 0to gain my first level of navigation.NewsSportIf a user clicks on News It reveals not only the existing levels but the new levels too in this case any name with a parental id of 1 as well so now ....News + Headlines+ Last WeekSportI have all this working fine .... now comes my problemIf a user then clicks Headlines it needs to reveal the next sub category within Headlines (these sub categories can be unlimited, which is where my code fails)I now need it to Present the headlines sub category...News+ Headlines + Wii Sells Out!!+ Last WeekSport And so on and so on ... for a possibility of an unlimited number of sub categories (this will not be the case but just incase)This is the code I have to do the first part...[code]<?phpsession_start();//open connection$conn = mysql_connect("localhost", "admin", "adm1n");mysql_select_db("links",$conn);$query = "SELECT `c_id`, `name`, `p_id` FROM `navtest` WHERE p_id = 0";$result = mysql_query($query) or die(mysql_error());$num = mysql_num_rows($result);if ($num > 0){ while ($row = mysql_fetch_array($result)){ $c_id = ($row['c_id']); $name = ($row['name']); $p_id = ($row['p_id']); echo "<a href=navtest2.php?c_id="; echo $c_id; echo ">"; echo $name; echo "</a>"; echo "<br />"; if ($c_id == $_GET['c_id']){ $qry = "SELECT * FROM `navtest` WHERE p_id = " . $_GET['c_id'] . " ORDER BY `name` ASC"; $qry = mysql_query($qry); while($row = mysql_fetch_assoc($qry)) { $c_id = ($row['c_id']); $name = ($row['name']); $p_id = ($row['p_id']); echo "<a href=navtest2.php?c_id="; echo $c_id; echo ">"; echo $name; echo "</a>"; echo "<br />"; //echo $row['name']; //echo "<br />"; }} }}else { echo "No links!!";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/28096-my-code-needs-better-logichelp/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.