help with FAQ page


#1

so i currently have the site set up like this

http://i.imgur.com/LQh9m.gif

i would like it so when a category is clicked, the questions then display below. from there you can click on the question and just the question and answer will appear i would like to do it by pageid or faqid in the page, no ajax or anything, can anyone help me or give me a good example, sorry im one of those people that learn by example
ive been reading alot on it but i get confused easily, thus why im looking for a example and someone experianced to help me, this site is a present for my boss and i hope to have it finished before i have to turn myself in on the 9th (not gunna go into details on that )


#2

by faqid/pageid i mean like faq.php?faqid=1&cat=2
so i can use mod_rewrite for better search engine optimization :slight_smile:


#3

So, this is a continuation of the previous post. You have the 9 FAQ categories now on the page. You can make these into <a HREF=FAQ.php?faqid=1&cat=2>faqname I think you already have that in place remembering your code. In this sample, the faqid would be the row# of the 1-of-9 numbers when you build the categories. The cat would be the actual question clicked on.

In the code after the FAQ categories are created, you would have the questions asked in a list.
These would be pulled from your questions/answers table in your database in a similar way as you
pulled your FAQ categories. Just like before. Only you do not have sort them into a 3x3 table.
Just loop thru them and display them. When someone presses on a different FAQ, it would go to the same page, just with a different FAQID selected. So, you would have to change your current page to read this argument and use it in the current display. To read this variable, you would do it something
like this: $currentfaq=$_GET[‘faqid’]; This would be in PHP code at the top of the page. Then, you would check to see if it was blank and if so, set it to the first faq. if($currentfaq="") $currentfaq=1;
Then, when you get down past the faq 3x3 display, and you start to display the actual questions, you use the $currentfaq variable to show just eh entries for that category. This, of course would be in your next MySQL query, something like “SELECT * FROM questions WHERE category=”.$currentfaq; or whatever…

I think that should get you started… Good luck, post back when you get stuck…


#4

thanks very much erniealex for all your help.
so in my page where my questions and ansers would go id put

$cat=$_GET['catid'];

then my sql under it like

mysql_select_db($database_local, $local); $query = mysql_query("SELECT Q FROM faq_cat where cat_id=$currentfaq"); then just echo $query?

my db is setup like this

tables
faq

  • id
  • Q
  • A
  • cat_id

faq_cat

  • id
  • name

is that right? im sorry if im slow and dont understand


#5

Don’t be sorry, coding is hard to get right sometimes. Thanks for the database layout, it helps…

SO, you have the faq_cat displayed in a 3x3 grid. Each one of those will have a HREF pointing back to this same page. In each of the HREF’s would be the ?faq_name=$name or whatever you want to indicate the name of the faq. For this part, when a user selects a new FAQ to view by pressing on one of the 9 links, they would be sent back to the same page, but, the variable “faq_name” would be passed, too.

Then, down your code a bit where you are ready to display the questions asked for a FAQ, you use the “faq_name” that is sent. You used “catid” in your samples. For the questions to be selected, you would use the FAQ name. So you retrieve it with $currentfaq=$_GET[[‘faq_name’]; Of course this “faq_name” is what I am calling it. It would be whatever you used in each of the HREF’s for the 9 FAQ selections.
Then, you query would be like this: (Almost the same as you had it!)
[php]
mysql_select_db($database_local, $local);
$query = mysql_query(“SELECT Q FROM faq where cat_id=$currentfaq”);
[/php]
This query will pull all Q’s from the database where they match the current FAQ that was selected by the user. Just remember if the $currentfaq was not selected, such as the first time you come to the page, then you have to tell your code to use the first FAQ…

On another note… You did not explain much about what is inside these FAQ’s. If there are not very many, you can just post them in the lower section. If there are hundred’s, most likely you will have to create a paging system to allow only so many to be shown at one time. Just something to think about…

Good luck


#6

Q = question
A = answer

question

<?php $currentfaq=$_GET['catid']; mysql_select_db($database_local, $local); $query = mysql_query("SELECT Q, A FROM faq where cat_id='".mysql_real_escape_string($currentfaq)."'"); while($cat = mysql_fetch_assoc($query)) echo ' <b>Question: </b>' . $cat['Q'] . '<br><br>'; echo '<b>Answer: </b>' . $cat['A'] . '<br>'; ?>

any reason why my answer is not being shown?


#7

nvm got it forgot my curly braces