Hey, Im mkaing a site, and I have a box, I just wanht like random facts to come in on everypage, ive seen this done. But im not sure if it was php.
Does anyboey know the code\
Thanks!
Cheers
maxx-designs
Random facts
Started by Maxx-Designs, Sep 26 2005 03:06 AM
5 replies to this topic
#1
Posted 26 September 2005 - 03:06 AM
#2
Posted 26 September 2005 - 04:09 AM
depending on what your are using (database wise) this is using MySQL
$fact = mysql_fetch_array(mysql_query("SELECT * FROM `facts` ORDER BY RAND()"));
echo $fact[0];
#3
Posted 26 September 2005 - 04:54 AM
im very n00b at php, i can do it databsae but can you put some example facts in there for me plz and teach mo how i cwould incopratre it
Thanks
Thanks
#4
Posted 26 September 2005 - 09:11 PM
Basically, you need to set up a mysql database. Create a table (according to illusions example, the table would be named facts). And then add the facts to the database.
To figure out how to use mysql, check out the tutorials in the database (http://www.pixel2life.com/tutorials/PHP_Co...1&d=1&ss=random or http://www.pixel2life.com/tutorials/PHP_Co...QL_Integration/) and php.net
$fact = mysql_fetch_array(mysql_query("SELECT * FROM `facts` ORDER BY RAND() LIMIT 1", MYSQL_NUM));
echo $fact[0];
Would actually be slightly better, because it would use less memory, and make things faster.To figure out how to use mysql, check out the tutorials in the database (http://www.pixel2life.com/tutorials/PHP_Co...1&d=1&ss=random or http://www.pixel2life.com/tutorials/PHP_Co...QL_Integration/) and php.net
#5
Posted 27 September 2005 - 01:02 AM
Thanks very much!
#6
Posted 27 September 2005 - 01:38 PM
<?php $facts = array ( 'This is fact 1', 'This is fact 2', 'This is fact 3', ); echo $facts[rand(0, count($facts)-1)]; ?>You can add more facts, just keep the structure that way
Edited by HaloprO, 27 September 2005 - 01:40 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
