Random Comment Selection

Reply

Join Date: Feb 2008
Posts: 2
Reputation: rommels is an unknown quantity at this point 
Solved Threads: 0
rommels rommels is offline Offline
Newbie Poster

Random Comment Selection

 
0
  #1
May 29th, 2008
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?


  1. <?php
  2. $host= "localhost";
  3. $user="username";
  4. $password="password";
  5. $dbname="dbname
  6. // connect to the database
  7. $cxn = mysqli_connect($host,$user,$password,$dbname)
  8. or die ("connection failed");
  9. // set the query to the variable so when used below it runs this query
  10. $entries="SELECT * FROM Review";
  11.  
  12. $result = mysqli_query($cxn,$entries)
  13. or die ("couldn't collect data");
  14. // counts and randomises between 1 and the returned query number
  15. $numresult = mysqli_num_rows($result);
  16. echo rand(1,$numresult);
  17.  
  18.  
  19. //below is the query that should select the record with the number in the variable numresult set above
  20.  
  21. // attempts to select all records from the table review where they = the number in the variable
  22. $name="SELECT * FROM Review WHERE id = $numresult";
  23. $nameresult = mysqli_query($cxn,$name)
  24. or die ("couldent get c name");
  25. //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.
  26. print_f $nameresult;
  27. ?>
  28.  

thanks in advance for any help
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 13
Reputation: pzuurveen is an unknown quantity at this point 
Solved Threads: 1
pzuurveen pzuurveen is offline Offline
Newbie Poster

Re: Random Comment Selection

 
0
  #2
May 30th, 2008
use mysql_real_escape_string to make our $name
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC