Page 1 of 1

Trouble with Tables

Posted: Sun Dec 26, 2010 9:22 pm
by mcgeepj2
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>");
}

Re: Trouble with Tables

Posted: Mon Dec 27, 2010 1:23 am
by social_experiment
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>';
?>
Just check the use of " with the printf() statement, mine might be prone to a syntax error.
Edit - Changed syntax.