Jump to content

Mixing html with php


dodgei

Recommended Posts

I'm having trouble mixing html code with php.

I want to display my database query result in a table with each field in a separate colomn.
I will be using a loop to access the records. Since I dont konw how many records will be
retrieved I dont know how many cells the table will have.

How can I create a new table row and <td> with each record retrieved?
Link to comment
https://forums.phpfreaks.com/topic/35596-mixing-html-with-php/
Share on other sites

Start your table before a while loop, and put your table row inside the loop and it will print a row for each result.

[code]
<?php

$query="SELECT * FROM table";
$result=mysql_query($query);
?>
<table width="50%" align="center" border="0">
<?php

while($row=mysql_fetch_assoc($result)){
echo '<tr><td>'.$row[fieldname].'</td><tr>';
}

?>
</table>[/code]
Link to comment
https://forums.phpfreaks.com/topic/35596-mixing-html-with-php/#findComment-168573
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.