Page 1 of 1

generating tables

Posted: Wed Dec 31, 2003 6:18 pm
by bluesman333
I'm trying to write a table: one row of images with a row beneath containing a checkbox with the same value as the image above and repeat this for every image in the query.

I'm not even close, but I've wrestled with it long enough and need some help. Here's what I have so far:

<table border=1>
<tr>
<?php

$count = 0;
while ($r = mysql_fetch_array($result)) {
$count++;
echo "\n<td><img src=\"/images/thumbnails/".$r['imagepath']."\"></td>";
if (($count % 4) == 0 ) { echo "</tr><tr>"; }
while ($r = mysql_fetch_array($result))
{$count++;
echo "\n<td><input name=\"images[]\" type=\"checkbox\" value=\"$r[imagepath]\"></td>"; }

if ($count % 8) { echo "</tr><tr>"; }

}
?>

</table>
</form>
<?php mysql_close( $link ); ?>

Posted: Wed Dec 31, 2003 9:30 pm
by m3rajk
is there a particular reason for going in and out of php?

Code: Select all

<?php
/* set up sql statements and other php stuff before any display starts */

$display="<html>
<head>
<!-- head info here -->
</head>
<body>\n"; # start the display

$data=mysql_query($sql, $db);
while($col=mysql_fetch_array($data){
$imgloc[]=$col['location'];
$boxdata[]=$col['boxdata'];
/* other column stuff */
}
$display.="<table><tbody><tr>\n";
foreach($imgloc  $as $img){
$display.="<td><img alt="something" src="$img" /></td>";
}
$display.="</tr>\n";
/*repeat that for each array */
$display.="</tbody></table>\n"

/* put the rest of everytying here */

echo $display;
?>

Posted: Thu Jan 01, 2004 1:05 am
by JAM
What about just adding a <br> and put the wanted values in a new line?

Code: Select all

<?php
$result = db( "SELECT * FROM test" );
$num_rows = mysql_num_rows($result);
?>
<table border="1">
<tr>
<?php
$count = 0;
while ($r = mysql_fetch_array($result)) {
    $count++;
    echo '<td align="center">
    '.$r['value'].'<br class="foo">'.
$r['WHATEVER']
    .'</td>';
    if (($count % 4) == 0 ) { echo "</tr><tr>\n"; }
}
?>
</table>

Posted: Thu Jan 01, 2004 7:57 pm
by bluesman333
I actually want to add several links below the image in it's own cell. I could use '<br>' but it would look neater in a new cell.