two mysql queries
i have to accomplish two tasks. and i want to do that in single query if possible.
task 1: i have to find out the maximum value of the column "id" and generate a random number between 1 and value from above.
task 2: use the random number in another query.
Can somebody please solve this.
i have written these seperate queries.
1 :
$query = "select MAX(id) from phpvar_in_mysqlquery";
$result = mysqli_query($dbc,$query) or die('error querying database');
$row = mysqli_fetch_array($result);
$number = rand(1,$row['MAX(id)']);
2 :
$query = "select * from phpvar_in_mysqlquery where id = $number";
$result = mysqli_query($dbc,$query) or die('error querying database');
$row = mysqli_fetch_array($result);
echo $row['id'].'<br />';
i have grabbed the maximum value in the first query and generated a random number.
i used the random number in the second query.
Subject
Written By
Posted
two mysql queries
August 19, 2012 01:00PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.