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. Link to comment https://forums.phpfreaks.com/topic/292521-inner-join-problem/ Share on other sites More sharing options...
Psycho Posted November 17, 2014 Share Posted November 17, 2014 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 Link to comment https://forums.phpfreaks.com/topic/292521-inner-join-problem/#findComment-1496805 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 Link to comment https://forums.phpfreaks.com/topic/292521-inner-join-problem/#findComment-1496809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.