essjay_d12 Posted November 21, 2006 Share Posted November 21, 2006 i have a database navlinks[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]Headlines[/td][td]1[/td][/tr][tr][td]3[/td][td]Sport[/td][td]0[/td][/tr][/table]I need the above table to print out like the following...NewsSportOnce news is clicked it will reveal its sub categories identified by WHERE p_id = News c_idso....News + HeadlinesSportThere can be an unlimited amount of subcategories and this is where im having problems ... ie looping!!anybody give me any hinters or help?cheersd Quote Link to comment https://forums.phpfreaks.com/topic/27966-help-with-structuring-php/ Share on other sites More sharing options...
ToonMariner Posted November 21, 2006 Share Posted November 21, 2006 [code]$qry = "SELECT * FROM `urtable` WHERE p_id = " . $_GET['c_id'] . " ORDER BY `name` ASC";$qry = mysql_query($qry);while($row = mysql_fetch_assoc($qry)){ echo $row['name'];}[/code]Obviously you will have to put your own html in there to make it look right!!! Quote Link to comment https://forums.phpfreaks.com/topic/27966-help-with-structuring-php/#findComment-127924 Share on other sites More sharing options...
essjay_d12 Posted November 21, 2006 Author Share Posted November 21, 2006 that works if there is only one sub category but it is unlimited so after a while the database could have been populated to look like the following.....News Headlines Today World war 3!!! Nintendo console Virus hits all Computers YesterdaySportetcany thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/27966-help-with-structuring-php/#findComment-127929 Share on other sites More sharing options...
ToonMariner Posted November 21, 2006 Share Posted November 21, 2006 well if you make the sub categories links just like you did the news one then the same will happen again... Quote Link to comment https://forums.phpfreaks.com/topic/27966-help-with-structuring-php/#findComment-127930 Share on other sites More sharing options...
essjay_d12 Posted November 21, 2006 Author Share Posted November 21, 2006 thanks Quote Link to comment https://forums.phpfreaks.com/topic/27966-help-with-structuring-php/#findComment-127935 Share on other sites More sharing options...
essjay_d12 Posted November 21, 2006 Author Share Posted November 21, 2006 this is what i got - but you said that if i made the next one a link it will work, however it doesnt....here is my code....it works to bring display the first sub category but when i click on the sub category to reveal its own subcategory it only displays the main two categories!![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] Quote Link to comment https://forums.phpfreaks.com/topic/27966-help-with-structuring-php/#findComment-127939 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.