mcmuney Posted February 16, 2008 Share Posted February 16, 2008 Looking for a simple random script, something like the one below where the script will take only one line: //Take one random line from below define('DEFAULT_TERM', 'Audi'); define('DEFAULT_TERM', 'Ford'); define('DEFAULT_TERM', 'Honda'); define('DEFAULT_TERM', 'Toyota'); Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/ Share on other sites More sharing options...
awpti Posted February 16, 2008 Share Posted February 16, 2008 Can we be a little less vague? Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468146 Share on other sites More sharing options...
phpSensei Posted February 16, 2008 Share Posted February 16, 2008 I am so confused with your question, but maybe this will help <?php $arr1 = array('Audi','Ford','Honda','Toyota'); $arr2 = array('Audi','Ford','Honda','Toyota'); $arr3 = array('Audi','Ford','Honda','Toyota'); $arr4 = array('Audi','Ford','Honda','Toyota'); shuffle($arr1); shuffle($arr2); shuffle($arr3); shuffle($arr4); //Take one random line from below define('DEFAULT_TERM', $arr1); define('DEFAULT_TERM', $arr2); define('DEFAULT_TERM', $arr3); define('DEFAULT_TERM', $arr4); ?> Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468161 Share on other sites More sharing options...
cyrixware Posted February 16, 2008 Share Posted February 16, 2008 Looking for a simple random script, something like the one below where the script will take only one line: //Take one random line from below define('DEFAULT_TERM', 'Audi'); define('DEFAULT_TERM', 'Ford'); define('DEFAULT_TERM', 'Honda'); define('DEFAULT_TERM', 'Toyota'); I was confuse about the question. If you want to use or make it random simply use MT_RAND() or RAND function (using dtabase). Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468191 Share on other sites More sharing options...
sKunKbad Posted February 16, 2008 Share Posted February 16, 2008 <?php session_start(); echo count($_SESSION['randomNums']) . "<br>"; print_r($_SESSION['randomNums']); function randomNoRepeat(){ $max= 6; $num = Rand (1,$max); if(isset($_SESSION['randomNums']) && in_array($num,$_SESSION['randomNums'])){ if (count($_SESSION['randomNums']) == 6){ switch ($num) { case 1: echo "Time is money"; break; case 2: echo "An apple a day keeps the doctor away"; break; case 3: echo "Elmo loves dorthy"; break; case 4: echo "Off to see the wizard"; break; case 5: echo "Tomorrow is another day"; break; case 6: echo "PHP is cool!"; } unset($_SESSION['randomNums']); }else{ randomNoRepeat(); } }else{ switch ($num) { case 1: echo "Time is money"; $_SESSION[randomNums][] = $num; break; case 2: echo "An apple a day keeps the doctor away"; $_SESSION[randomNums][] = $num; break; case 3: echo "Elmo loves dorthy"; $_SESSION[randomNums][] = $num; break; case 4: echo "Off to see the wizard"; $_SESSION[randomNums][] = $num; break; case 5: echo "Tomorrow is another day"; $_SESSION[randomNums][] = $num; break; case 6: echo "PHP is cool!"; $_SESSION[randomNums][] = $num; } } } randomNoRepeat(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468209 Share on other sites More sharing options...
phpSensei Posted February 16, 2008 Share Posted February 16, 2008 He Wants The PHP script to take a link below(randomly): define('DEFAULT_TERM', 'Audi'); define('DEFAULT_TERM', 'Ford'); define('DEFAULT_TERM', 'Honda'); define('DEFAULT_TERM', 'Toyota'); Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468211 Share on other sites More sharing options...
mcmuney Posted February 16, 2008 Author Share Posted February 16, 2008 I'm not using the database for this. I just want the script to randomly take only 1 of those lines each time the script is loaded. I didn't realize the questions was so vague. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468213 Share on other sites More sharing options...
sKunKbad Posted February 16, 2008 Share Posted February 16, 2008 So just modify the script. I cut and pasted it as an example. I'm not going to do all of the work. It shouldn't be hard to modify, even for a beginner. Quote Link to comment https://forums.phpfreaks.com/topic/91361-random-script/#findComment-468221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.