Mix html and php

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

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Mix html and php

Post 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>
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Mix html and php

Post 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
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Mix html and php

Post by mariolopes »

Thank you
Post Reply