Hi everyone, tried to display next and previous records from the coding below but unable to do so.It suppose to display next records for the current user with the when user click "Next" but currently it doesn't display "Next" but only display "Random". When i clicked "Random", it displays next records for all users. The following message also is displayed ie "Champ: 'picid' dans field list est ambiguRandom". The same goes to "Previous". Please advise.
Thanks.
<?php
error_reporting(E_ALL ^ E_NOTICE);
$host = 'localhost';
$user = 'user';
$pass = '';
$dbname = 'pq';
$con = mysqli_connect($host, $user, $pass,$dbname);
if(!$con){
die('Could not connect: '.mysqli_connect_error());
}
$_SESSION['userid']; // it will print the userid value
$currentId = mysqli_real_escape_string($con,$_GET['picid']);
if($q = mysqli_query($con, 'SELECT *,
(SELECT IFNULL(max(picid),-1) FROM general,progress WHERE userid='.$_SESSION['userid'].' and `general.picid` < '.$currentId.') as previousid,
(SELECT IFNULL(min(picid),-1) FROM general,progress WHERE userid='.$_SESSION['userid'].' and `general.picid` > '.$currentId.') as nextid
FROM general,progress WHERE `general.picid` = ' . $currentId)){
if($row = mysqli_fetch_array($q, MYSQL_BOTH)){
echo '<div id="picid">picid' . $row['picid'] . '</div>';
echo '<div id="userid">userid ' . $row['userid'] . '</div>';
echo '<div id="progress">progress ' . $row['progress'] . '</div>';
echo '<div id="Rating">Rating ' . $row['Rating'] . '</div>';
if ($row['previousid'] > -1){
echo '<a href="progress.php?picid='.$row['previousid'].'"class="random">Previous</a>';
}
if ($row['nextid'] > -1){
echo '<a href="progress.php?picid='.$row['nextid'].'"class="random">Next</a>';
}
} else {
echo 'Not found';
}
} else {
echo mysqli_error($con);
}
echo "</div>";
$query = "select * from general,progress order by RAND() LIMIT 1";
$result = mysqli_query($con, $query) or die("Query failed: " . mysqli_errno($con));
while ($row = mysqli_fetch_array($result, MYSQL_BOTH)){
echo '<a href="ipdprogress.php?picid='.$row['picid'].'"class="random">Random</a>';
}
mysqli_close($con);
?>