Ran into an issue with a script I am writing, and hey, I have never posted on this board...figured I would toss it out here since I am overlooking something.
2 Tables - cats and subcats. The c_autonum = s_cat below...so that ties the two tables together.
CATS fields = c_autonum, c_title
SUBCATS fields = s_autonum, s_cat, s_title, s_desc
I am trying to get information to display in the following format, but having no luck, and have a mental block at the moment.
1. (c_title) General Questions?
- (s_title) What is this?
- (s_title) Why are we here?
2. (c_title) Specific Questions?
- (s_title) Exactly what is this?
- (s_title) Why do we press this button?
Here is my code:
<?php <br /><br />// declare variables and make the database connection <br /><br />MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); <br />@mysql_select_db( "$dbName") or die( "Unable to select database"); <br /><br />// query information for faq <br /><br />$result = mysql_query("SELECT * FROM cats,subcats WHERE c_autonum=s_cat"); <br />$i = 1; <br />if ($myrow = mysql_fetch_array($result)) { <br /><br />// display list if there are records to display <br /><br /> do { <br /> printf("%s. <a href=%s>%s</a><br /> %s. %s<br />\n", <br /> $myrow["c_autonum"], <br /> $PHP_SELF, <br /> $myrow["c_title"], <br /> $i, <br /> $myrow["s_title"]); <br />$i++; <br /> } while ($myrow = mysql_fetch_array($result)); <br /> } <br /><br />else {echo "Sorry, nothing found!"; <br /> } <br />?>
This is WORKING...just not correctly. It is showing up with the category above everyone sub-category...ie:
1. (c_title) General Questions?
- (s_title) What is this?
1. (c_title) General Questions?
- (s_title) Why are we here?
Is there a quick fix for this?