orbitter Posted March 2, 2008 Share Posted March 2, 2008 ??? hi there is it possible to store a number of different php scripts in a mysql database and then output them randomly??? pleaseeeeee help :'( Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/ Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 Elaborate a little more please, and provide some more details. I understood you want to put different scripts in your database, and output them randomly. Correct? <?php $res = mysql_query ("select * from my_scripts"); $num = mysql_num_rows($res); $random = rand(1,$num); $query = mysql_query ("select * from my_scripts where id=$random"); ?> Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481670 Share on other sites More sharing options...
orbitter Posted March 2, 2008 Author Share Posted March 2, 2008 basically what i have is a few php scripts, i want to be able to store these php scripts into a mysql database, and then be able to output these scripts in a random order. can you help me please? is there anything else you need to know? thank you Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481674 Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 basically what i have is a few php scripts, i want to be able to store these php scripts into a mysql database, and then be able to output these scripts in a random order. can you help me please? is there anything else you need to know? thank you Use the script i provided, and insert the script with a INSERT COMMAND in mysql. It randomizes the IDs of the scripts to be shown in a random order. make sure your table has ID in it, or change it to your own. Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481683 Share on other sites More sharing options...
orbitter Posted March 2, 2008 Author Share Posted March 2, 2008 thanks for the help, could you please show me an example of how my table should look like please?? Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481690 Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 thanks for the help, could you please show me an example of how my table should look like please?? by scripts, what do you mean? TABLES Create Table 'my_scripts' ------------ id INT(11) UNSIGNED AUTO_INCREMENT, script_name VARCHAR(22) NOT NULL, UNIQUE KEY(id) Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481691 Share on other sites More sharing options...
orbitter Posted March 2, 2008 Author Share Posted March 2, 2008 by scripts i mean individual php files. is this what the code that you provided me does? input the files into the table and then randmomise the output? Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481692 Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 To insert the scripts <?php $script1 = "file1.php"; mysql_query("INSERT INTO my_scripts (script_name) VALUES ('$script1')"); $script2 = "file2.php"; mysql_query("INSERT INTO my_scripts (script_name) VALUES ('$script2')"); $script3 = "file3.php"; mysql_query("INSERT INTO my_scripts (script_name) VALUES ('$script3')"); ?> To Get The Files in random order: <?php $query = mysql_query("SELECT * FROM my_scripts ORDER BY rand()"); while($row = mysql_fetch_array($query)){ echo $row['script_name'] . '<br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481697 Share on other sites More sharing options...
orbitter Posted March 2, 2008 Author Share Posted March 2, 2008 sorry about my crap explanation maybe i will be better at explaining with an example. i have 3 files lets say: //hello.php <?php echo 'Hello World!'; ?> //goodbye.php <?php echo 'goodbye world!'; ?> //morning.php <?php echo 'morning World!'; ?> what i want to do is input these 3 different files into a mysql table, and then when i output them, their output should be random. could you help pleasE? Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481705 Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 Oh dear god, thats what my script does. man, did you even try it? Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481713 Share on other sites More sharing options...
orbitter Posted March 2, 2008 Author Share Posted March 2, 2008 thanks for the script, i posted my thing at the same time you sent your other script. sorry about that. Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481714 Share on other sites More sharing options...
phpSensei Posted March 2, 2008 Share Posted March 2, 2008 thanks for the script, i posted my thing at the same time you sent your other script. sorry about that. Oh, its okay. Sorry man, just having a really rough day. Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481716 Share on other sites More sharing options...
orbitter Posted March 2, 2008 Author Share Posted March 2, 2008 tell me about it been having a few of those recentely. im gona try using the script now. really appreciate the help, thanks. Link to comment https://forums.phpfreaks.com/topic/94021-php-script-randomisation-and-storing-into-database/#findComment-481723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.