PDA

View Full Version : Need Help !


HormonX
10-13-2002, 03:07 AM
This is fairly simple... but for some reason i have a problem ( as always ) :)

ok .. i have a pull down menu with questions, if i select a question from a list an answer should be pulled form the database and displayed on thesame page .

I have go the menu to display the questions, the problem i have is with displaying the answers. below is the code for pulling the questions from the database


<?
include ('connect.php');
$query = "SELECT * FROM faq";

$result = mysql_query( $query, $link );
?>
<option>Please Select a Question</option>
<?
while($r=mysql_fetch_array($result))
{
$faq_id=$r['faq_id'];
$q = $r['q'];
echo "<option value='faq.php?faq_id=$faq_id'>$q</option><br>";
}
?>



I came up with this code to get the answers .. but it still doesn't work.


if(!$faq_id)
{
echo "";
}
else
{
$query = "SELECT * FROM faq WHERE faq_id='$faq_id'";
$result = mysql_query( $query, $link );

while($r=mysql_fetch_array($result))
{
$a=$r['a'];

echo "$a";
}


and in fact nothing is displayed ... what am i missing ?

hope you can help

HormonX

firepages
10-13-2002, 08:00 AM
... dont know what version of PHP you are running , but the does your setup 'see' $faq_id OR $_POST['faq_id']

$HTTP_POST_VARS is a compromise which should work regardless

best way to debug this sort of stuff is to echo any errors etc to screen and to echo flags to see where the problem is occurring... i.e.


<?
if(!$HTTP_POST_VARS['faq_id'])
{
echo "$faq_id not set - check your form";
}else{
echo "$faq_id exists, running query<br />";
$query = "SELECT * FROM faq WHERE faq_id='$faq_id'";
$result = mysql_query( $query, $link )or die("database error ".mysql_error());

if(!@mysql_num_rows($result))
{
while($r=mysql_fetch_array($result))
{
$a=$r['a'];
echo "$a";
}
}else{
echo "no rows returned from database";
}
}
?>

HormonX
10-14-2002, 01:58 AM
well i just setup a Merlin server .. that includes apache, mysql and php in one. But when i want to see results on the screen i only need to use $variable.

anyhow ... i have figured it out ... and it works works just great ...

thanx again for your help

HormonX