Page 1 of 1

Can I put php inside html that is inside php?

Posted: Tue Feb 09, 2010 10:23 am
by CraneVallon
On my user form I want a select option from a list that is built new each time from the contents of the database. Therefore I open php to find the list of row contents (I'm using the column called 'team'), then I tell the html to display a list of these elements in the select option. That's okay, say the team in the third row is Brighton then the third select option is Brighton. But I also need to individually name that third value in order to return it through POST for processing. In other words, I can't get the html to accept the value of the item. Here's my code (the html select name multiple etc are outside this block):

$result = mysql_query("SELECT * FROM assoTel");
while ($row = mysql_fetch_array($result))
{
echo "<
option value=\"
<?php
echo $row['name'];
?>
\"
>"
.$row['name']."</option><br/>";
}
mysql_free_result($result);

Re: Can I put php inside html that is inside php?

Posted: Tue Feb 09, 2010 10:27 am
by jefffan24
echo "<option value=" . $row['name'] . "continue your html";

Make sure you close your quotations put a . then put your php put another . then open your quotations and continue like nothing happened :D