script for FAQ page
Posted: Mon Dec 20, 2010 5:10 am
Hi everyone,
i am trying to write a script for an faq page, presently all the questions are stored in a database. i want the page to function as the one in this url http://www.magentocommerce.com/product/faq.
here is what i have been able to do. presently it fetches the question and answer from the database but now i will like for it to work this way: like if i click on a link it automatically jumps to the area on the same page. so how do i associate each links with content from the database???
function main()
{
$rs= mysql_query("SELECT * FROM faq WHERE status='1' ORDER BY faqorder");
echo "<H1>Frequently Asked Questions and my answers</H1>";
echo "If you have a question that has not been addressed below, please ask it in the text box at the bottom of this page
and I will answer it online and if appropriate put it on the website anonymously for others to benefit from as soon as possible.<br/>";
?>
<div id="faq_list">
<ul>
<li> <a href="#<?php echo $value['id']?>"> Is treatment Painful? </a></li>
<li> <a href=""> Will treatment take a long time? </a></li>
<li> <a href=""> How much will it cost? </a></li>
</ul>
</div>
<div class="table faq"> </div>
<?php
//var_dump(mysql_fetch_array($rs));exit;
while($value=mysql_fetch_array($rs))
{
//var_dump($value);
$question=stripslashes($value['question']);
$answer=stripslashes($value['answer']);
$ques=str_replace("?","",$question);
$ques=str_replace("!","",$question);
$ques=str_replace(" ","_",$question);
?>
<p id="faq">
<strong>Q. <?php echo $question;?></strong><br/>
<strong>A.</strong> <?php echo $answer;?>
</p>
<br/>
<?php
thanks.
i am trying to write a script for an faq page, presently all the questions are stored in a database. i want the page to function as the one in this url http://www.magentocommerce.com/product/faq.
here is what i have been able to do. presently it fetches the question and answer from the database but now i will like for it to work this way: like if i click on a link it automatically jumps to the area on the same page. so how do i associate each links with content from the database???
function main()
{
$rs= mysql_query("SELECT * FROM faq WHERE status='1' ORDER BY faqorder");
echo "<H1>Frequently Asked Questions and my answers</H1>";
echo "If you have a question that has not been addressed below, please ask it in the text box at the bottom of this page
and I will answer it online and if appropriate put it on the website anonymously for others to benefit from as soon as possible.<br/>";
?>
<div id="faq_list">
<ul>
<li> <a href="#<?php echo $value['id']?>"> Is treatment Painful? </a></li>
<li> <a href=""> Will treatment take a long time? </a></li>
<li> <a href=""> How much will it cost? </a></li>
</ul>
</div>
<div class="table faq"> </div>
<?php
//var_dump(mysql_fetch_array($rs));exit;
while($value=mysql_fetch_array($rs))
{
//var_dump($value);
$question=stripslashes($value['question']);
$answer=stripslashes($value['answer']);
$ques=str_replace("?","",$question);
$ques=str_replace("!","",$question);
$ques=str_replace(" ","_",$question);
?>
<p id="faq">
<strong>Q. <?php echo $question;?></strong><br/>
<strong>A.</strong> <?php echo $answer;?>
</p>
<br/>
<?php
thanks.