mad4it Posted February 19, 2008 Share Posted February 19, 2008 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 https://forums.phpfreaks.com/topic/91930-calling-a-php-file-within-html-to-return-a-result/ Share on other sites More sharing options...
duclet Posted February 19, 2008 Share Posted February 19, 2008 Kinda of a weird way of doing things but you can just use include('script.php?n=1'); Link to comment https://forums.phpfreaks.com/topic/91930-calling-a-php-file-within-html-to-return-a-result/#findComment-470758 Share on other sites More sharing options...
mad4it Posted February 19, 2008 Author Share Posted February 19, 2008 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 https://forums.phpfreaks.com/topic/91930-calling-a-php-file-within-html-to-return-a-result/#findComment-470842 Share on other sites More sharing options...
duclet Posted February 20, 2008 Share Posted February 20, 2008 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 https://forums.phpfreaks.com/topic/91930-calling-a-php-file-within-html-to-return-a-result/#findComment-471213 Share on other sites More sharing options...
mad4it Posted February 26, 2008 Author Share Posted February 26, 2008 Worked brilliantly, thanks! Link to comment https://forums.phpfreaks.com/topic/91930-calling-a-php-file-within-html-to-return-a-result/#findComment-477012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.