Step 5 - Displaying the faq from the database
We have everything we need now except our faq.php page which displays the questions!
So create a new file called faq.php
and put this in it:
<?
include 'config.php'; // includes config file
echo "Choose a question:<br/>"; // writes Choose a question:
$mq = mysql_query("SELECT * FROM `faq` "); // the variable is the mysql query which selects from the table faq
while($display = mysql_fetch_array($mq)) { // using the while function which defines display = mysql fetch array $mq which gets the contents of the $mq variable
$qslct = $display[faqname]; // variable = $display[faqname]
echo "<a href='#$qslct'>$qslct</a><br/>"; // write the following...
}
echo "<br/><br/>"; // writes break lines ...
$dmq = mysql_query("SELECT * FROM `faq` "); // and we start the fetch proccess again...
while($displayqaa = mysql_fetch_array($dmq)) {
$qtell = $displayqaa[faqname];
$qansw = $displayqaa[faqanswer];
echo "<span id='$qtell'>Q: $qtell<br/>A: $qansw</span><br/><br/>";
}
?>
Ok so once you have put that into your file I am now going to tell you what it means.
Basically the file includes the config file which tells it how to connect to the database, thats that part and then the rest is simple fetching it from the database with the mysql_fetch_array snippet and echoing data, thats all!
Pages: « First 2 3 4 5 6 Last »
Share
del.icio.us
Digg it
reddit
Current tags
Rate this tutorial
4
|
Log In to rate this tutorial
|
Comments
PricelessNL on 04/03/07 at 12:38
hi, i found youre tutorial on the web when i was searching for a tut to create a faq. first i want to say nice tutorial :)
but i have a question. Is there a possibillity of a Edit.php page where you could edit the questions or answers if you made a error
Add Comment
Log In to post your comments