Jump to content

Recommended Posts

Does anyone know why this table join doesnt work

 

$result = mysql_query("
SELECT t.departureDate, t.expireDate, t.airport, t.destination, t.resort, t.hotel, t.duration, t.board, t.price, t.description, t.customerRef, t.mystiqueRef, t.stars, c.departureDate, c.expireDate, c.airport, c.destination, c.resort, c.hotel, c.duration, c.board, c.price, c.description, c.customerRef, c.mystiqueRef, c.stars
FROM test AS t LEFT JOIN cyprus AS c
ON t.customerRef = c.customerRef 
WHERE c.customerRef OR t.customerRef LIKE '%$search%'") or die(mysql_error());

 

When i search one table it with this its ok

 

$result = mysql_query("SELECT departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, description, customerRef, mystiqueRef, stars FROM test WHERE customerRef LIKE '%$search%'");

 

but with the join the search shows no results?

Link to comment
https://forums.phpfreaks.com/topic/138985-table-joins/
Share on other sites

it doesnt show an error. Does it look correct?

 

Its to be used to display results based on a reference number being searched (customerRef). Although say a do a search for a reference number I know that is in the test table it just displays nothing, same vice verser

Link to comment
https://forums.phpfreaks.com/topic/138985-table-joins/#findComment-726879
Share on other sites

Because you're doing a LEFT JOIN, you should only search on the left table field t.customerRef.  The LEFT JOIN says that you want all rows from left table (for the predicate) and only rows from right table that match left table on customerREF.

 

Try this instead:

 

$result = mysql_query("

SELECT t.departureDate, t.expireDate, t.airport, t.destination, t.resort, t.hotel, t.duration, t.board, t.price, t.description, t.customerRef, t.mystiqueRef, t.stars, c.departureDate, c.expireDate, c.airport, c.destination, c.resort, c.hotel, c.duration, c.board, c.price, c.description, c.customerRef, c.mystiqueRef, c.stars

FROM test AS t

LEFT JOIN cyprus AS c

ON t.customerRef = c.customerRef

WHERE t.customerRef LIKE '%$search%'") or die(mysql_error());

 

Link to comment
https://forums.phpfreaks.com/topic/138985-table-joins/#findComment-726935
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.