Jump to content

random images in a table


aml

Recommended Posts

Hi all.

Wondering if I can achieve this goal, with your help of course :D

 

I have a table (4 rows x 4 lines) with 16 images; each one has a link to open in a bigger size or an html page.

I want my images change the position, randomly in that table, each time the page is loaded or refreshed.

Is that possible using PHP? Should I use another different technology? By the way, I’m using Dreamweaver for design.

 

Thanks in advance

aml

 

 

 

Link to comment
Share on other sites

Hi Alex,

first of all thanks for your reply.

Basically, this is on row of my table:

 

          <tr>

            <td><div align="center"><a href="mariza.html" target="_blank"><img src="imagens/mariza/main.jpg" width="220" height="240" border="0"></a></div></td>

            <td><div align="center"><a href="anaraquel.html" target="_blank"><img src="imagens/anaraquel/main.jpg" width="220" height="240" border="0"></a></div></td>

            <td><div align="center"><a href="joicy.html" target="_blank"><img src="imagens/joicy/main.jpg" width="220" height="240" border="0"></a></div></div></td>

            <td><div align="center"><a href="rita.html" target="_blank"><img src="imagens/rita/main.jpg" width="220" height="240" border="0"></a></div></td>

          </tr>

         

As I told you before, the idea is to have all images displayed in a different position each time the page loads…

Hope this helps to better understand the idea 

 

Cheers,

aml

 

Link to comment
Share on other sites

You could do something like..

 

<?php
$imgs = Array(Array('mariza', 'main.jpg'), Array('anaraquel', 'main.jpg'), Array('joicy', 'main.jpg'), Array('rita', 'main.jpg'));
shuffle($imgs);
?>

<tr>
            <td><div align="center"><a href="<?php echo $imgs[0][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[0][0] . '/' . $imgs[0][1]; ?>" width="220" height="240" border="0"></a></div></td>
            <td><div align="center"><a href="<?php echo $imgs[1][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[1][0] . '/' . $imgs[1][1]; ?>" width="220" height="240" border="0"></a></div></td>
            <td><div align="center"><a href="<?php echo $imgs[2][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[2][0] . '/' . $imgs[2][1]; ?>" width="220" height="240" border="0"></a></div></div></td>
            <td><div align="center"><a href="<?php echo $imgs[3][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[3][0] . '/' . $imgs[3][1]; ?>" width="220" height="240" border="0"></a></div></td>
          </tr>

Link to comment
Share on other sites

Yea, something like this..

 

<?php
$imgs = Array(Array('mariza', 'main.jpg'), Array('anaraquel', 'main.jpg'), Array('joicy', 'main.jpg'), Array('rita', 'main.jpg'));
shuffle($imgs);

echo "<tr>";
foreach($imgs as $img)
{
     echo '<td><div align="center"><a href="' . $img[0] . '.html" target="_blank"><img src="imagens/' . $img[0] . '/' . $img[1] . '" width="220" height="240" border="0"></a></div></td>';
}
echo "</tr>";

 

Then just add more content to the Array to display more. The thing is, you'll have to edit that so it'll work for adding more rows.

Link to comment
Share on other sites

<?php
$imgs = Array(
	Array('mariza', 'main.jpg'), 
	Array('anaraquel', 'main.jpg'),
	Array('joicy', 'main.jpg'),
	Array('rita', 'main.jpg')
);
shuffle($imgs);

echo "<table><tr>";
$width = 4;
$cw = 1;
foreach($imgs as $img) {
	if ($cw == $width) { echo "</tr><tr>"; $cw = 1; }
	echo '<td><div align="center"><a href="' . $img[0] . '.html" target="_blank"><img src="imagens/' . $img[0] . '/' . $img[1] . '" width="220" height="240" border="0"></a></div></td>';
	$cw++;
}
while ($cw < 4) {
	echo "<td> </td>";
}
echo "</tr></table>";
?>

 

building off of alex's post

Link to comment
Share on other sites

Hi all.

sorry to bother again :)

cannot put this code working properlly...

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<?php

$imgs = Array(

Array('a', 'main.jpg'),

Array('b', 'main.jpg'),

Array('c', 'main.jpg'),

Array('d', 'main.jpg')

);

shuffle($imgs);

 

echo "<table><tr>";

$width = 4;

$cw = 1;

foreach($imgs as $img) {

if ($cw == $width) { echo "</tr><tr>"; $cw = 1; }

echo '<td><div align="center"><a href="' . $img[0] . '.html" target="_blank"><img src="imagens/' . $img[0] . '/' . $img[1] . '" width="220" height="240" border="0"></a></div></td>';

$cw++;

}

while ($cw < 4) {

echo "<td> </td>";

}

echo "</tr></table>";

?>

<html>

<head>

</head>

<body>

<table width="920" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#312F30">     

 

  <tr>

            <td><div align="center"><a href="<?php echo $imgs[0][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[0][0] . '/' . $imgs[0][1]; ?>" width="220" height="240" border="0"></a></div></td>

            <td><div align="center"><a href="<?php echo $imgs[1][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[1][0] . '/' . $imgs[1][1]; ?>" width="220" height="240" border="0"></a></div></td>

            <td><div align="center"><a href="<?php echo $imgs[2][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[2][0] . '/' . $imgs[2][1]; ?>" width="220" height="240" border="0"></a></div></div></td>

            <td><div align="center"><a href="<?php echo $imgs[3][0]; ?>.html" target="_blank"><img src="imagens/<?php echo $imgs[3][0] . '/' . $imgs[3][1]; ?>" width="220" height="240" border="0"></a></div></td>

          </tr>

               

</table></td>

  </tr>

</table>

</body>

</html>

 

What am I doing wrong? ( a lot of things I imagine... :) )

 

Cheers,

aml

Link to comment
Share on other sites

You have to put the PHP code where you want the content to be. Not in the head.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body> 
<table width="920" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#312F30">      
<?php
   $imgs = Array(
      Array('a', 'main.jpg'), 
      Array('b', 'main.jpg'),
      Array('c', 'main.jpg'),
      Array('d', 'main.jpg')      
   );
   shuffle($imgs);

   echo "<tr>";
   $width = 4;
   $cw = 1;
   foreach($imgs as $img) {
      if ($cw == $width) { echo "</tr><tr>"; $cw = 1; }
      echo '<td><div align="center"><a href="' . $img[0] . '.html" target="_blank"><img src="imagens/' . $img[0] . '/' . $img[1] . '" width="220" height="240" border="0"></a></div></td>';
      $cw++;
   }
   while ($cw < 4) {
      echo "<td> </td>";
   }
   echo "</tr>";
?>
</table>
</body>
</html>

Link to comment
Share on other sites

Hi Russel,

the algorithm seems to work great :D sweet

however, the table structure was changed..  I have the first row with 3 pictures and a second row with just only one picture...

additionally, I have an extra column with four rows that present 4 pictures, one per row and all aligned at right... :S strange behavior...

could you help me find out what the problem is?

cheers,

aml

 

Link to comment
Share on other sites

Hi all.

maybe I didn't explain myself correctly; what append with this code is:

it's supposed to have a table with one row with the all 4 pictures, and  I have  a couple of rows:

the first one with 3 pictures and a second row with the remaining picture of the 4 images sequence. then, I have more 4 rows and each one display one picture (with always the same sequence as the first one)

 

can someone help me find out what the problem is?

thanks in advance

aml

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.