generating tables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
bluesman333
Forum Commoner
Posts: 52
Joined: Wed Dec 31, 2003 9:47 am

generating tables

Post 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 ); ?>
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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;
?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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>
User avatar
bluesman333
Forum Commoner
Posts: 52
Joined: Wed Dec 31, 2003 9:47 am

Post 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.
Post Reply