I needed a real simple Q&A script on a site...and this is a very easy setup.
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.
(c_title) General Questions?
(s_title) What is this?
(s_title) Why are we here?
(c_title) Specific Questions?
(s_title) Exactly what is this?
(s_title) Why do we press this button?
Here is my code:
<?php
// declare variables and make the database connection
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
// query information for faq
$result = mysql_query("SELECT * FROM cats,subcats WHERE c_autonum=s_cat");
$i = 1;
if ($myrow = mysql_fetch_array($result)) {
// display list if there are records to display
do {
printf("%s. <a href=%s>%s</a><br /> %s. %s<br />\n",
$myrow["c_autonum"],
$PHP_SELF,
$myrow["c_title"],
$i,
$myrow["s_title"]);
$i++;
} while ($myrow = mysql_fetch_array($result));
}
else {echo "Sorry, nothing found!";
}
?>
This is WORKING...just not correctly. It is showing up with the category above everyone sub-category...ie:
- (c_title) General Questions?
- (s_title) What is this?
- (c_title) General Questions?
- (s_title) Why are we here?
Is there a quick fix for this? I could not find any other questions like this.