Page 1 of 1

Mix html and php

Posted: Tue Jan 12, 2010 6:40 am
by mariolopes
Hi
I want to show all the records from my tabla and i need to mix php and html. I try the following but i get error. Please help
<?php
$mysql_id = mysql_connect('localhost', 'curso', '123');
mysql_select_db('vendas',$mysql_id);

$query='Select * from noite';

$result=mysql_query($query);
?>
/*construçao da tabela */
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<table border="1">
<?php
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><?php print $row['Nome'];?></td>
<td><?php print $row['Idade'];?></td>
</tr>
}
</table>
</html>

Re: Mix html and php

Posted: Tue Jan 12, 2010 6:43 am
by aravona

Code: Select all

<?php
$mysql_id = mysql_connect('localhost', 'curso', '123');
mysql_select_db('vendas',$mysql_id);
 
$query='Select * from noite';
 
$result=mysql_query($query);
?>
/*construçao da tabela */
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<table border="1">
<?php
while($row=mysql_fetch_array($result)){
?>
<tr>
<td><?php print $row['Nome'];?></td>
<td><?php print $row['Idade'];?></td>
</tr>
<?php
}
?>
</table>
</html>
Your close for your while loop was in html - try that and see if it works

Re: Mix html and php

Posted: Tue Jan 12, 2010 6:50 am
by mariolopes
Thank you