Forum Moderators: coopster

Message Too Old, No Replies

php/mysql images in rows

         

sionvalais

12:07 pm on Nov 8, 2003 (gmt 0)

10+ Year Member



I want to define a template where div's define rows with 3 images. the number of rows therefore depends on the number of images.
something like this
-------
img1 img2 img3
-------
img4 img5 img6
-------
img7 img8 imgx
-------

Has anyone an idea?

cheers,

Mark

RonPK

4:13 pm on Nov 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$numberOfRowsNeeded = ceil($numberOfImages / 3);

sionvalais

8:53 pm on Nov 10, 2003 (gmt 0)

10+ Year Member



That is not really what I mean; I want to know how I cam line up three images within a div. Each div as a row.
So I have e.g. 24 images in a database and I want to exhibit them in 8 rows of three images, but without using classic tables.

DrDoc

9:01 pm on Nov 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's one way:


Style sheet:

.fl {
float: left;
}
.cl {
clear: left;
}

PHP script:

<?php
for($i=1; $i<=$numOfImgs; $i ++) {
echo "<img src=\"" . $img[$i-1] . "\" class=\"fl";
if($i%3 === 0) {
echo " cl";
}
echo "\">";
}
?>

Every third image will be on a new line.

sun818

9:19 pm on Nov 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Heehee, I must be the only one that still uses tables! ;) You can divide the current record number by three (mod 3) and insert a </tr><tr> every third record.

<table>
<tr>

<!--loop start-->
<!--START IF=rownum==4-->
</tr>
<tr>
<!--END IF-->
<!--START IF=rownum==7-->
</tr>
<tr>
<!--END IF-->
<td>content</td>
<!--loop end-->

</tr>
</table>

I suggest you run your HTML output through a validator as you experiment.

DrDoc

9:31 pm on Nov 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



...except that sionvalais didn't want to use tables ;)

Plus, I assume it needs to handle an unknown number of images, and always put only three per row, right?

sionvalais

7:25 am on Nov 12, 2003 (gmt 0)

10+ Year Member



your right doc, thank you.

cheers,

sionvalais

sionvalais

9:42 am on Nov 15, 2003 (gmt 0)

10+ Year Member



There is something not working. $row->camurl is the url of the webcams. What else do i need to change?

<?

$query="select * from sionvalais where resort=resort";

$result=mysql_query($query)
or die(mysql_error());

echo "";

while ($row=mysql_fetch_object($result))
{

for($i=1; $i<=$numOfImgs; $i ++) {
echo "<img src=\"" . $row->camurl[$i-1] . "\" class=\"fl";
if($i%3 === 0) {
echo " cl";
}
echo "\">";
}
?>

coopster

11:32 am on Nov 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



First things first...

Whenever working with string and date values in MySQL you should specify them as quoted strings:


$query="select * from sionvalais where resort='resort'";

>>There is something not working. $row->camurl is the url of the webcams.

Are you getting an error message, no data returned...? Can you offer more detail?

RonPK

11:34 am on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, more detail please.

Also, try replacing

echo "<img src=\"" . $row->camurl[$i-1] . "\" class=\"fl";

with

echo '<img src="' . $row->camurl . '" class="fl';

sionvalais

6:55 pm on Nov 15, 2003 (gmt 0)

10+ Year Member




ok, this is what I use, and the error message is:
Parse error: parse error in /home/.sites/107/site233/web/test.php on line 48
(which is the last line </html>)

<?

$query="select * from sionvalais where resort='resort'";

$result=mysql_query($query)
or die(mysql_error());

echo "";

while ($row=mysql_fetch_object($result))
{

for($i=1; $i<=$numOfImgs; $i ++) {
echo '<img src="' . $row->camurl . '" class="fl';;
if($i%3 === 0) {
echo " cl";
}
echo "\">";
}
?>

coopster

10:02 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You need one more closing brace (}) as you forgot to close your
while
loop.

sionvalais

11:12 pm on Nov 15, 2003 (gmt 0)

10+ Year Member



no content is rendered. what kind of refence do I have to make to the database for numOfImgs?