Randomise Code

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
sitmex
Forum Newbie
Posts: 1
Joined: Mon Jun 09, 2008 11:44 pm
Location: Guadalajara, Mexico

Randomise Code

Post by sitmex »

Hi,

I had an idea tonight that I might implement on my site, but I don't know how to proceed since I'm a newbie in PHP programming.

I have a web template that has three blocks of information on the right side, and three on the bottom of the page.

The blocks on the right, three of them, looks like this (all in spanish):
Intention for the blocks: To promote services offered

Code: Select all

 
<div class="right_articles">
    <p><img src="images/image1.gif" alt="Image" title="Image" class="image" /><b>M&aacute;s Valor por su Dinero </b><br />
                Consulte la sección de nuestros <a href="paqhosp.php">paquetes de hospedaje</a> para sitios web y correos electr&oacute;nicos y conozca que podemos hacer por usted o su empresa.</p>
</div>
 
Then the blocks on the bottom looks like this:
Intention for the blocks: Internet Glossary.

Code: Select all

 
<div class="thirds">
                <p><b><a href="cms.php" class="title">Gestor de Contenidos</a></b><br />
                        Los Sistemas de Gesti&oacute;n de Contenidos son generalmente usados para crear, editar, administrar y publicar de manera consistentemente organizada contenido como, noticias, manuales, documentos t&eacute;cnicos y publicidad mediante distintos medios (sigue...) <a href="cms.php"><img src="images/comment.gif" alt="Comment" /></a></p>
            </div>
 
What I would like to do is: Write a number of blocks (with the code in it) in a text file to randomly display them as the different pages of the website loads.

I've seen examples of random text, using arrays like this:

Code: Select all

 
<?php
$random = array
(
    array
    (
        "image" => "image1.jpg",
        "quote" => "quote one",
        "link_url" => "http://www.domain.com/?id=1",
        "link_text" => "link one"
    ),
    array
    (
        "image" => "image2.jpg",
        "quote" => "quote two",
        "link_url" => "http://www.domain.com/?id=2",
        "link_text" => "link two"
    )
);
$i = mt_rand(0, count($random) - 1);
$size = "";
 
if(file_exists($random[$i]['image']))
{
    $size = " ".array_slice(getimagesize($random[$i]['image']), 3, 1);
}
?>
<table border="0" align="center" cellpadding="0" cellspacing="8">
  <tr>
    <td><img src="<?php echo $random[$i]['image']; ?>"<?php echo $size; ?> alt="<?php echo $random[$i]['image']; ?>"></td>
  </tr>
  <tr>
    <td><?php echo $random[$i]['quote']; ?></td>
  </tr>
  <tr>
    <td align="center"><a href="<?php echo $random[$i]['link_url']; ?>"><?php echo $random[$i]['link_text']; ?></a></td>
  </tr>
</table>
 
I would like to avoid arrays since I think that uploading a text file (built outside the server) would be easier to implement, rather than modifying a php file.

Is this feasible? any ideas or suggestions?

Help would be very much appreciated.

Thanks in Advance.
Post Reply