| | |
Random Comment Selection
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Solved Threads: 0
Hello, im new coding in php, iv got a good backing in programming but as far as this goes im a tad lost. to start i and decided to go with a simple script that counts the rows in a mySQL database returns a result, randomises between 1 and that result and then should select and display that record
unfortunatly it seems to break down after the "randomise" part, any ideas?
thanks in advance for any help
unfortunatly it seems to break down after the "randomise" part, any ideas?
PHP Syntax (Toggle Plain Text)
<?php $host= "localhost"; $user="username"; $password="password"; $dbname="dbname // connect to the database $cxn = mysqli_connect($host,$user,$password,$dbname) or die ("connection failed"); // set the query to the variable so when used below it runs this query $entries="SELECT * FROM Review"; $result = mysqli_query($cxn,$entries) or die ("couldn't collect data"); // counts and randomises between 1 and the returned query number $numresult = mysqli_num_rows($result); echo rand(1,$numresult); //below is the query that should select the record with the number in the variable numresult set above // attempts to select all records from the table review where they = the number in the variable $name="SELECT * FROM Review WHERE id = $numresult"; $nameresult = mysqli_query($cxn,$name) or die ("couldent get c name"); //print or echo the result, eventually i hope to use an array to hold for e.g the comment, first name and last name for indervidual use. print_f $nameresult; ?>
thanks in advance for any help
![]() |
Similar Threads
- RE: Leaked Windows Source Code (IT Professionals' Lounge)
Other Threads in the PHP Forum
- Previous Thread: N level menu navigation
- Next Thread: Rendering emoticons onto image - conflicting
| Thread Tools | Search this Thread |
.htaccess ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl customizableitems database date delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime google host href htaccess html image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm mod_rewrite multiple mysql navigation oop parsing paypal pdf php problem query radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube





