PDA

View Full Version : Single Selection from PHP File



Diversions
09-07-2008, 01:49 PM
I am attempting to set up a separate php file that will allow me to randomly pull one line for placement into a page. I have tried the following "array" but I can only get it down to 2 lines. I am beginning to understand php now a little better and I have tried finding the answer in the PHP site only to go cross-eyed. Any direction here would be a big help.

Current PHP code:

<?php
srand((float) microtime() * 10000000);
$input = array(
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
'<a target="_blank" href="" title="">XXX</a><br>',
);
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
?>

The link to pull it is standard
<?php include("directorylist.php"); ?>

Many thanks
D

techietim
09-07-2008, 03:21 PM
Should be this:


$rand_key = array_rand($input);
echo $input[$rand_key] . "\n";

$rand_key isn't an array when you're only calling one item.

Diversions
09-07-2008, 03:30 PM
Makes perfect sense when someone explains it. Thank you so much for the help techietim it works a charm and solves the remaining immediate problem.