PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
stom
Forum Newbie
Posts: 6 Joined: Thu Mar 11, 2010 1:04 pm
Post
by stom » Tue Mar 30, 2010 3:11 pm
Hi I am trying to fetch values from the database and place it in the listbox within a div using php. This is what I am trying.
Code: Select all
<DIV>
<P>Cancer Data</P>
<UL id="Cancer Data">
<?php
$link = connectToDB(); // this is a funciton to connect to DB
$strQuery = "select * from cancertype";
$result = mysql_query($strQuery) or die(mysql_error());
if ($result) {
while($rs1= mysql_fetch_array($result)) {
$value = $rs1['cancername'];
echo("<LI id= ".$value."> ".$value."</LI> ");
}
}
mysql_close($link);
?>
</UL>
</DIV>
But the php code doesnt seem to be functioning. The div is displaying the following
Code: Select all
.$value.""); } }
mysql_close($link);
?>
Someone please tell me what I am doing wrong!!!
Thanks!
Last edited by
Benjamin on Tue Mar 30, 2010 3:14 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
cpetercarter
Forum Contributor
Posts: 474 Joined: Sat Jul 25, 2009 2:00 am
Post
by cpetercarter » Tue Mar 30, 2010 3:59 pm
Try replacing
Code: Select all
echo("<LI id= ".$value."> ".$value."</LI> ");
with
Code: Select all
echo "<li id=\"" . $value . "\">" . $value . "</li>";
stom
Forum Newbie
Posts: 6 Joined: Thu Mar 11, 2010 1:04 pm
Post
by stom » Tue Mar 30, 2010 4:10 pm
Thanks...
but I found the mistake... The file was initially an html file... so forgot to change the file name to ".php" .
This is embarrassing!!!...
bt guess I wil not repeat it again... learn from mistakes...