Jump to content

Calling a php file within html to return a result.


mad4it

Recommended Posts

I've got an html file that calls a php file in 3 places, and depending on whats passed in, 3 different pieces of info is passed back.

 

Iteration 1:

<img src="script.php?i=1"> - which returns the image name pertaining to position 1 in my array.

 

Iteration 2:

<a href="script.php?l=1"> - which returns the hyperlink relating to the same image.

 

Iteration 3:

This is the bit i'm stuck on. I need to effectively call script.php?n=1 to get the title for the image but as I want to display it as plain text I dont know how to call it as obviously if I just put script.php?n=1 in the html it will display exactly that as text rather than the result of the php script.

 

I know doing the whole page in php would have solved this but its a change to an already well placed page in the search engines so the client would prefer to keep the existing name.

 

Anyone got any suggestions on how I call the script in iteration 3?

 

Thanks in advance!

 

 

Thats cool thanks, got one more problem.

 

I have 3 arrays each with the same number of elements.

 

I need to randomise the arrays so that they are moved into a random order but the relationship between the 3 arrays remain ie image x still ties up with link x with name x.

 

I was using this code but this doesnt seem to quite do the trick :

 

$secondsFixed=900;

$seedValue=(int)(time()/$secondsFixed);

srand($seedValue);

 

for ($i=0;$i<$total;++$i)

{

$r=rand(0,$total-1);

$temp =$images[$i];

$images[$i]=$images[$r];

$images[$r]=$temp;

$temp =$links[$i];

$links[$i]=$links[$r];

$links[$r]=$temp;

$temp =$names[$i];

$names[$i]=$names[$r];

$names[$r]=$temp;

}

 

 

I get duplicate names in the list, what have I done wrong?

Wouldn't it be better to combine all the data as one and then randomize that? Example:

<?php
$images = array('array of images');
$links = array('array of links');
$names = array('array of names');
$length = count($images);

// Create a single array
$data = array();
for($i = 0; $i < $length; ++$i) {
    $data[] = array(
        'image' => $images[$i],
        'link'  => $links[$i],
        'name'  => $names[$i]
    );
}

// Now randomly select an item
$item = $data[mt_rand(0, $length-1)];

// Do something with item
printf('<a href="%s" alt="%s"><img src="%s" /></a>',
       $item['link'], $item['name'], $item['image']);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.