Jump to content

INNER JOIN problem


Lopez

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.