Could some one please help me with the code below. I'll explain what Im trying to do.
Basically, I have an FAQ application and I'm looping to output the question category and all the answers for that category. At the moment it diplaying all the categoties on top and then all the questions for all categories. Would you please help with a way of having to display a category with the answers for that category then the next and so on based on the code Im providing below...Your help with be much appreciated. Many thanks in advance.
Code: Select all
if(isset($_GET['q_id'])) { $q_id = $_GET['q_id']; }
if($q_id != "") {
$question_query = mysql_query("SELECT * FROM faq_questions WHERE q_id='$q_id'");
$question = mysql_fetch_assoc($question_query);
if(mysql_num_rows($question_query) == 0) {
echo "<h2>An error has occurred:</h2>
You are attempting to view an FAQ question that does not exist.
";
}
$answerQ = "
<b>$question[question]</b><br><br>
$question[answer]
<form action='/.../help/$LANG' method='POST'>
<input type='submit' value='Back to FAQ'>
</form>
";
} else {
// IF USER IS LOOKING AT THE MAIN PAGE
$totalcount = 0;
$faq_questions = mysql_query("SELECT * FROM FROM faq_questions");
$faqcat = mysql_query("SELECT * FROM faq_categories ORDER BY c_order ASC");
$num_of_kitties = mysql_num_rows($faqcat);
while($faqcat_info = mysql_fetch_assoc($faqcat)) {
$questions = mysql_query("SELECT q_id, c_id, question FROM faq_questions WHERE c_id='$faqcat_info[c_id]' ORDER BY q_order");
// SHOW CATEGORY NAME, IF IT CONTAINS QUESTIONS AND CATEGORY NAMES ARE TURNED ON
if(mysql_num_rows($questions) > 0) {
$faqcat_infomain = "<b>$faqcat_info[category]</b>";
}
// SHOW QUESTIONS
$count = 0;
while($question = mysql_fetch_assoc($questions)) {
$totalcount++;
$count++;
// SHOW NUMBERS IF ENABLED
if($admin_info[shownumbers] == 1) {
if($admin_info[showcats] == 1) { echo "$count. "; } else { echo "$totalcount. "; }
}
$Questionmain .= $count." <a href='/.../help/$LANG?q_id=$question[q_id]'>$question[question]</a><br>";
$Questionmain = $faqcat_infomain."<br>".$Questionmain;
//echo $Questionmain;
}