Jump to content

INNER JOIN problem


Go to solution Solved by Psycho,

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

  • Solution

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 by Psycho
Link to comment
https://forums.phpfreaks.com/topic/292521-inner-join-problem/#findComment-1496805
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.