Lopez Posted November 17, 2014 Share Posted November 17, 2014 Hello guys. Thanks a lot for any help with this. My problem is that I'm trying to use MAX to get the last item in the portafolio table. This is my query: $result = $db->prepare( "SELECT * FROM portafolio INNER JOIN imagenes ON imagenes.work = portafolio.idp WHERE work = ? ORDER BY iid DESC); $result->execute(array($_GET['work'])); The main idea is not use $_GET['work'], because i want to display the last work (with their respective images) in my portafolio in the main page, so im not passing any variable by url. Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted November 17, 2014 Solution Share Posted November 17, 2014 (edited) You know that code is invalid, right? There is no closing quote for the query definition. If you want the last item added, then you should be using a timestamp field to determine that and not the id field. I'm guessing 'iid' is the id field? Assuming all you have is the id field (and you aren't going to fix it), it might look something like this SELECT * FROM portafolio INNER JOIN imagenes ON imagenes.work = portafolio.idp WHERE iid = (SELECT MAX(iid) FROM portafolio) ORDER BY iid DESC Edited November 17, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
Lopez Posted November 17, 2014 Author Share Posted November 17, 2014 Psycho, Thanks a lot! Thats works perfectly Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.