Page 1 of 1

using php within a div tag

Posted: Tue Mar 30, 2010 3:11 pm
by stom
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!

Re: using php within a div tag

Posted: Tue Mar 30, 2010 3:59 pm
by cpetercarter
Try replacing

Code: Select all

echo("<LI id= ".$value."> ".$value."</LI> ");
with

Code: Select all

echo "<li id=\"" . $value . "\">" . $value . "</li>";

Re: using php within a div tag

Posted: Tue Mar 30, 2010 4:10 pm
by stom
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!!!... :oops:
bt guess I wil not repeat it again... learn from mistakes...