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?

<?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 :)

This article has been dead for over six months. Start a new discussion instead.