Joshua F
June 27th, 2010, 04:35
I made a really simple Did You Know system, it uses MySql to get the ID of the Did you know fast, and also to get the did you know fact. It randomizes it on everyload.
*.php
Did you Know?<br>
- <?php
DEFINE ('DB_HOST', 'localhost'); // This will most likely stay the same.
DEFINE ('DB_USER', 'USER'); // Insert your database username into the quotes.
DEFINE ('DB_PASSWORD', 'PASS'); // Insert your database password into the quotes.
DEFINE ('DB_NAME', 'Database');// Insert your actual database name in the quotes.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );
$list_q = mysql_query("SELECT * FROM dyk") or die (mysql_error());
while($list_f = mysql_fetch_assoc($list_q)) {
$storeArray[] = $list_f['dyk'];
}
$random_number = rand(0,(count($storeArray) - 1));
echo $storeArray[$random_number];
?>
MySQL Import:
CREATE TABLE IF NOT EXISTS `dyk` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`dyk` varchar(75) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
Just insert the php code to were you want it, and edit it how you wish. This is just a simple one, nothing special.. Might make a simple Add.php also, depends if Im in the mood..
*.php
Did you Know?<br>
- <?php
DEFINE ('DB_HOST', 'localhost'); // This will most likely stay the same.
DEFINE ('DB_USER', 'USER'); // Insert your database username into the quotes.
DEFINE ('DB_PASSWORD', 'PASS'); // Insert your database password into the quotes.
DEFINE ('DB_NAME', 'Database');// Insert your actual database name in the quotes.
$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());
mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );
$list_q = mysql_query("SELECT * FROM dyk") or die (mysql_error());
while($list_f = mysql_fetch_assoc($list_q)) {
$storeArray[] = $list_f['dyk'];
}
$random_number = rand(0,(count($storeArray) - 1));
echo $storeArray[$random_number];
?>
MySQL Import:
CREATE TABLE IF NOT EXISTS `dyk` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`dyk` varchar(75) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0 ;
Just insert the php code to were you want it, and edit it how you wish. This is just a simple one, nothing special.. Might make a simple Add.php also, depends if Im in the mood..