Jump to content

Bill Withers

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by Bill Withers

  1. Thank you! This worked $query = "SELECT course_name FROM courses ORDER BY RAND()LIMIT 1"; $result = mysql_query($query) or trigger_error(mysql_error()." ".$query); $row = mysql_fetch_assoc($result); $course = $row["course_name"];
  2. hello all, Currently I am doing this via txt files and it works fine, but I want to save space/resources and along the way learn something. I am having a problem creating a table to retrieve random data with php. I am not sure how to setup the table structure Here's what I tried so far table info CREATE TABLE courses ( ID smallint(6) NOT NULL AUTO_INCREMENT, Course_name varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (ID) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=12 ; Then I insert the data INSERT INTO courses (ID, Course_name)VALUES(1, 'Sawgrass'); INSERT INTO courses (ID, Course_name)VALUES(2, 'Riviera CC'); INSERT INTO courses (ID, Course_name)VALUES(3, 'Bethpage'); INSERT INTO courses (ID, Course_name)VALUES(4, 'Torrey Pines'); INSERT INTO courses (ID, Course_name)VALUES(5, 'Sheshan Golf Club'); INSERT INTO courses (ID, Course_name)VALUES(6, 'St Andrews'); INSERT INTO courses (ID, Course_name)VALUES(7, 'Pebble Beach'); INSERT INTO courses (ID, Course_name)VALUES(8, 'Harbour Town'); INSERT INTO courses (ID, Course_name)VALUES(9, 'Oakmont'); INSERT INTO courses (ID, Course_name)VALUES(10, 'Bay Hill'); INSERT INTO courses (ID, Course_name)VALUES(11, 'refstack CC); INSERT INTO courses (ID, Course_name)VALUES(12, 'Cove Beach'); Then I try to retrieve this data randomly and put into a string $course <?php include ('db.php'); $connection = new createConnection(); //i created a new object $connection->connectToDatabase(); // connected to the database $linkid = $_GET['ID']; $query = "SELECT * FROM course_name order by rand() limit 1"; $result = mysql_query($query); $course= $row ['course_name']; ?> Then try to put this into a table <td><font face="Arial, Helvetica, sans-serif"><?php echo $course; ?></font></td> It errors out saying there is nothing in the database to retrieve. Would be grateful if someone could point me in the right direction php 5.4 mysql 5.5
×
×
  • 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.