0

This is my problem. I have a table like this:

enter image description here

I used this code to select max pictureID for each different user. Every user uploaded many pictures. The only problem is that it works only of 2 columns. Picture Name is not updated, it doesn't match with the picture ID... How can I improve this selection to get the right picture?

   include('connection.php'); 
//  WHERE user_name = '$myuser'
$sql = "SELECT user_name, picture, MAX(pictid) FROM `pictures` group by user_name"; 
$result = $mysqli->query($sql);

if ($result->num_rows > 0) {
  // output data of each row

while($row = $result->fetch_assoc()) {
    
//$obrazek = $row["picture"]; 

    echo "<tr><td>". $row["user_name"]. "</td><td>". $row['MAX(pictid)']. "</td><td>". $row["picture"]. "</td></tr>";

  }
}
Michael
  • 25
  • 3

0 Answers0