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!

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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']);
?>

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.