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.
script for FAQ page
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: script for FAQ page
You already have part of the question half-answered. To go to a specific area on a page you have to use anchors (html).quickLearner wrote:so how do i associate each links with content from the database???
Code: Select all
<a href="#top">Top</a>
// and the anchor is
<a name="top"></a>
Code: Select all
<?php
// assume the PK is 'id'
$select = mysql_query("SELECT * FROM table");
while ($array = mysql_fetch_array($select)) {
// links would have the following format
echo '<a href="page.php?#'. $array['id'] .'">Link</a>';
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering