Jump to content

php script randomisation and storing into database!


orbitter

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.