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 :'( Quote Link to comment 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"); ?> Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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?? Quote Link to comment 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) Quote Link to comment 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? Quote Link to comment 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>'; } ?> Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.