Greetings all please forgive me for I am just beginning with php. My immediate problem is trying to get the below output to result in a table with the 2 cells for each field side by side. I can't get the printf line formatted correctly. Any help?
$result = mysql_query(
"SELECT * FROM `units` ORDER BY `field_1` ASC LIMIT 0, 30 ");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
printf("<P>" . " %s %s", $row["field_1"], $row["field_2"] . "</P>");
}
Trouble with Tables
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Trouble with Tables
mcgeepj2 wrote:My immediate problem is trying to get the below output to result in a table with the 2 cells for each field side by side.
Code: Select all
<?php
$result = mysql_query(
"SELECT * FROM `units` ORDER BY `field_1` ASC LIMIT 0, 30 ");
if (!$result) {
echo("<P>Error performing query: " .
mysql_error() . "</P>");
exit();
}
echo '<table>';
while ( $row = mysql_fetch_array($result) ) {
printf("<td>" . " %s %s", $row["field_1"] ."</td><td>". $row["field_2"] . "</td>");
}
echo '</table>';
?>Edit - Changed syntax.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering