"John Bass" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi All,
>
> I am trying to generate a table with two columns. Each column should
print
> 2 fields named image_link and web_url. Have spent over week looking
> documentations and trying different coding but nothing is working. Any
help
> will be greatly appreciated.
The other answers are generally correct but a bit hard to follow.
Try this:
<?php
// declare variables
$col = 0;
$numcols = 0;
// == fn startTable ===============
function startTable($columns) {
global $col, $numcols;
// reset variables
$col = 0;
$numcols = (int) $columns;
// start table
echo "\n<table>";
}
// === fn addColumn ==============
function addColumn($str) {
global $col, $numcols;
// first column? start row
if ($col == 0)
echo "\n\t<tr>";
// echo cell contents
echo "\n\t\t<td>$str</td>";
// last column? end row and reset
$col++;
if ($col == $numcols) {
echo "\n\t</tr>";
$col = 0;
}
}
// ==== fn endTable ===============
function endTable() {
global $col, $numcols;
// pad the table as necessary
for ($i = $col; $i < $numcols; $i++)
addColumn(' ');
// end table
echo "\n</table>";
}
// ======= MAIN =================
mysql_connect("host", "user", "pwd")
or die("Error connecting: ".mysql_error());
$query = "SELECT image_link,web_url FROM testdata";
$result = mysql_db_query("db", $query)
or die("Error querying: ".mysql_error());
startTable(2);
while ($row = mysql_fetch_array($result))
addColumn( $row["image_link"].'<br>'.$row["web_url"] );
endTable();
?>
How's that?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]