Page 1 of 1
Newbie question about pictures and tables
Posted: Mon Dec 30, 2002 6:58 am
by kooijt
Hi,
I have question about a gallery i'm trying to setup. First let me show the code I have so far:
Code: Select all
if ($keuze == 'Klas') {
$query = "SELECT llnr, roepnaam, achternaam FROM
leerlingen WHERE klas = '$klas' ORDER BY achternaam_sort";
} elseif ($keuze == 'Leerlingnummer') {
$query = "SELECT llnr, roepnaam, achternaam FROM
leerlingen WHERE llnr = '$klas'";
}
$result = mysql_query ($query)
or die ("Query failed");
// printing HTML result
echo "<br>";
echo "<b><font size="5">Resultaat:</font></b>";
echo "<center><p><b><font size="5">$klas</font></b></p></center>";
echo "<table align="center">\n";
// now display your fields
while ($line = mysql_fetch_array($result)) {
echo "<tr>\n";
$llnnr = $lineї"llnr"];
echo "<td width="100" height="150"><p><center><a href="leerling.php"><img border="0" name="$llnnr" src="/images/foto/$llnnr
.jpg" width=100 height=150></p></a></center></td>\n";
echo "</tr><tr><td align="center">";
echo $lineї"roepnaam"];
echo " ";
echo $lineї"achternaam"];
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>";
This displays the images fine, but underneath each other, and i want them in a row of 5 by 6 pixtures maximum. Can someone point me in the rigth direction?
regards,
Theodoor van der Kooij.
Posted: Mon Dec 30, 2002 7:48 am
by Johnm
kooijt,
Look through this thread.
viewtopic.php?t=4616&highlight=
and let us know if you need more help.
John M
Posted: Mon Dec 30, 2002 8:09 am
by kooijt
It produced the same result. This is the new code, correct me please if i did something wrong:
Code: Select all
echo "<table>\n";
// now display your fields
//while ($line = mysql_fetch_array($result)) {
for ($i=0;$line = mysql_fetch_array($result);$i++) {
if (($i != 0) && (($i % 5) == 0))
$llnnr = $lineї"llnr"];
echo "<td width="100" height="150"><p><center><a href="leerling.php"><img border="0" name="$llnnr" src="/images/foto/$llnn$
echo "</tr><tr><td align="center">";
echo $lineї"roepnaam"];
echo " ";
echo $lineї"achternaam"];
echo "</td>\n";
echo "</tr>\n";
if (($i != 0) && (($i % 5) == 0))
echo "</tr>\n";
}
echo "</table>";
Posted: Mon Dec 30, 2002 8:34 am
by Johnm
Try adding a border to the table to see where things are lined up. That may shed some light on things.
John M
Posted: Mon Dec 30, 2002 8:49 am
by kooijt
I did this, the result is shown @
http://web.ghlyceum.nl/test/smoel.php , choose "klas" and fill in 6v4.
I think i missed something, but i can't see what.
Theodoor van der Kooij.
Posted: Mon Dec 30, 2002 9:13 am
by Johnm
I see, if you "View Sorce" on that page you will see that the <tr></tr> tags are bring sent to the browser for each image where as you only want it sent for each block of five.
John M
Posted: Mon Dec 30, 2002 9:56 am
by kooijt
OK, i changed the code a bit, but now the names are not corresponding with the photos:
Code: Select all
echo "<table border="1">\n";
echo "<tr>";
// now display your fields
//while ($line = mysql_fetch_array($result)) {
for ($i=0;$line = mysql_fetch_array($result);$i++) {
if (($i != 0) && (($i % 5) == 0))
$llnnr = $lineї"llnr"];
echo "<td width="100" height="150"><p><center><a href="leerling.php"><img border="0" name="$llnnr" src="/images/foto/$llnn$
echo "<td align="center">";
echo $lineї"roepnaam"];
echo " ";
echo $lineї"achternaam"];
echo "</td>\n";
if (($i != 0) && (($i % 5) == 0))
echo "</tr>\n";
}
echo "</tr>\n";
echo "</table>";
When i throw in a few <tr>'s the names are corresponding with the photo's, but then they are underneath each other again
Theodoor van der Kooij.
Posted: Mon Dec 30, 2002 10:06 am
by Johnm
So, you mean that you want the names under the photo?
John M
Posted: Mon Dec 30, 2002 10:10 am
by kooijt
That is one of the possibility's, but the names are not matching the photo's, i want to correct that first.
Theodoor van der Kooij.
Posted: Mon Dec 30, 2002 10:24 am
by Elmseeker
Try this:
Code: Select all
<?
$query = "SELECT * FROM your_table";
$result = mysql_db_query("yourdbname",$query);
echo "<table ALIGN=CENTER width="90%" cellspacing="0" cellpadding="0" border="0"><TR>";
/* print */
while($row =mysql_fetch_array($result)){
$i = $row[0];
echo "<td align="center">";
echo $line["roepnaam"];
echo " ";
echo $line["achternaam"];
echo "</td>\n";
if ( is_int($i / 5 )) {
echo "</TR><TR>";
}
}
echo "</TR></TABLE>";
?>
This will display the pictures 5 across and as many down as needed until it goes through the entire table, you can use offsets and limits in here to make it only display 30 pictures at a time 5 across and 6 down if you want but this is just an example...
Posted: Mon Dec 30, 2002 10:40 am
by Johnm
So the name to the right of each pic is not the correct name?
Try this:
Code: Select all
<?php
echo "<table border="1">\n";
// now display your fields
//while ($line = mysql_fetch_array($result)) {
for ($i=0;$line = mysql_fetch_array($result);$i++)
{
if (($i != 0) && (($i % 5) == 0))
{
echo "<tr>\n";
}
$llnnr = $line["llnr"];
echo "<td width="100" height="150"><p><center>\n";
echo "<a href="leerling.php"><img border="0" name="$llnnr" src="/images/foto/$llnn$\n";
echo "<br> \n";
echo $line["roepnaam"]."\n";
echo " \n";
echo $line["achternaam"]."\n";
echo "</td>\n";
if (($i != 0) && (($i % 5) == 0))
{
echo "</tr>\n";
}
}
echo "</table>";
?>
John M
Posted: Mon Dec 30, 2002 12:11 pm
by kooijt
I'm getting there thnx, it now does some weird thing with the rows, but i'll play with that. Very much thanks for your help. If i still have problems i come back with you.
Theodoor van der Kooij.
Posted: Mon Dec 30, 2002 4:43 pm
by kooijt
Hi,
i didn't figure it out yet. I think it is in this piece of code, but i don't understand it:
Code: Select all
if (($i != 0) && (($i % 5) == 0))
{
echo "<tr>\n";
}
Can someone lighten me up?
Theodoor van der Kooij
Posted: Tue Dec 31, 2002 4:38 am
by kooijt
OK, now it's perfect. This is the code i'm using right now:
Code: Select all
echo "<table width="100%" align="center">\n";
// now display your fields
//while ($line = mysql_fetch_array($result)) {
for ($i=0;$line = mysql_fetch_array($result);$i++)
{
if (($i != 0) && (($i % 5) == 0))
{
echo "<tr>\n";
}
$llnnr = $lineї"llnr"];
echo "<td align="center" width="100" height="150"><p>\n";
echo "<a href="leerling.php"><img border="0" name="$llnnr" src="/images/foto/$llnnr.jpg" width=100 height=150></p></a>\n";
echo "<br>\n";
echo $lineї"roepnaam"]."\n";
echo " \n";
echo $lineї"achternaam"]."\n";
echo "</td>\n";
if (($i !=0) && (($i % 19) == 0))
{
echo "</tr>\n";
}
}
echo "</table>";
Thnx for the outstanding help!
Theodoor van der Kooij.