Newbie question about pictures and tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Newbie question about pictures and tables

Post 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)) &#123;
        echo "<tr>\n";
        $llnnr = $line&#1111;"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&#1111;"roepnaam"];
        echo "&nbsp;";
        echo $line&#1111;"achternaam"];
        echo "</td>\n";
        echo "</tr>\n";
&#125;

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.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

kooijt,
Look through this thread.
viewtopic.php?t=4616&highlight=
and let us know if you need more help.
John M
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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)) &#123;
for ($i=0;$line = mysql_fetch_array($result);$i++) &#123;
        if (($i != 0) && (($i % 5) == 0))
        $llnnr = $line&#1111;"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&#1111;"roepnaam"];
        echo "&nbsp;";
        echo $line&#1111;"achternaam"];
        echo "</td>\n";
        echo "</tr>\n";
        if (($i != 0) && (($i % 5) == 0))
          echo "</tr>\n";
&#125;

echo "</table>";
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Try adding a border to the table to see where things are lined up. That may shed some light on things.

Code: Select all

echo "<table border=1>\n";


John M
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post 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
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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)) &#123;
for ($i=0;$line = mysql_fetch_array($result);$i++) &#123;
        if (($i != 0) && (($i % 5) == 0))
        $llnnr = $line&#1111;"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&#1111;"roepnaam"];
        echo "&nbsp;";
        echo $line&#1111;"achternaam"];
        echo "</td>\n";
        if (($i != 0) && (($i % 5) == 0))
          echo "</tr>\n";
&#125;

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.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

So, you mean that you want the names under the photo?

John M
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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.
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post 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...
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post 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
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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.
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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))
   &#123; 
        echo "<tr>\n";    
   &#125;
Can someone lighten me up?

Theodoor van der Kooij
kooijt
Forum Newbie
Posts: 8
Joined: Mon Dec 30, 2002 6:58 am
Location: Netherlands
Contact:

Post 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)) &#123;
for ($i=0;$line = mysql_fetch_array($result);$i++)
&#123;

   if (($i != 0) && (($i % 5) == 0))
   &#123;
        echo "<tr>\n";
   &#125;

        $llnnr = $line&#1111;"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&#1111;"roepnaam"]."\n";
        echo " \n";
        echo $line&#1111;"achternaam"]."\n";
        echo "</td>\n";

        if (($i !=0) && (($i % 19) == 0))
        &#123;
                echo "</tr>\n";
        &#125;
&#125;

echo "</table>";
Thnx for the outstanding help!

Theodoor van der Kooij.
Post Reply