Jump to content

Where is this query going wrong? Something to do with the WHERE part....


Recommended Posts

Hi,

 

Got a wierd prob with a query string, and here it is:

 

SELECT bi.id, bi.author_id, bi.firstname, bi.secondname, bi.thirdname, bi.fourthname, bi.fifthname, bi.surname, bi.dates, bi.biography, bi.created, au.name AS author, au.id AS auth_id
FROM jos_yearbook_biographies bi
LEFT JOIN jos_yearbook_authors au ON bi.author_id = au.id
WHERE bi.author_id = '1'
AND bi.surname LIKE 'cuy%'
OR bi.firstname LIKE 'cuy%'
OR bi.secondname LIKE 'cuy%'
OR bi.thirdname LIKE 'cuy%'
OR bi.fourthname LIKE 'cuy%'
OR bi.fifthname LIKE 'cuy%'
OR bi.biography LIKE '%cuy%'

 

The problem is with the author_id - it seems to ignore it completely, and shows a result regardless.  In the DB I've got two items, one with author_id 1, and the other with 2.

 

It shows the item with an author_id of two every time - I've checked the code, and it's sending 1 as seen in the statement.

 

I've also tried it using this statement:

 

SELECT bi.*, au.name AS author, au.id AS auth_id FROM #__yearbook_biographies bi 
				LEFT JOIN #__yearbook_authors au ON bi.author_id = au.id WHERE bi.surname LIKE 'cuy%'
			OR bi.firstname LIKE 'cuy%' 
			OR bi.secondname LIKE 'cuy%' 
			OR bi.thirdname LIKE 'cuy%' 
			OR bi.fourthname LIKE 'cuy%' 
			OR bi.fifthname LIKE 'cuy%' 
			OR bi.biography LIKE '%cuy%' AND bi.author_id = '1'

 

(I know one has jos_ and the other has #__ - I was testing the variant in phpmyadmin)

 

Any ideas why I always get items with author_id of '2'???  Puzzled.

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.