Jump to content

Recommended Posts

The following query does not work and I have no idea why. I have a feeling that it is something to do with the LIKE?

$search_query = mysql_query("SELECT DISTINCT
				threadID
			    FROM
				forum_posts
			    WHERE
				postSubject LIKE '%find me%'
				AND posterID = '1'");

 

The error is in that it will get all DISTINCT threadID's regardless of the posterID that got sent. I.e. If you searched 'find me' by bob, it will get 'find me' by bob and 'find me' by fred and 'find me' by me and 'find me' you. It is only meant to display 'find me' by bob.

 

Any help is greatly appreciated.

Joe.

Link to comment
https://forums.phpfreaks.com/topic/240096-mysql-select-not-working/
Share on other sites

I don't see anything wrong with your LIKE syntax, or the rest of the query for that matter. Perhaps it's actually pulling out the correct thing and it's the database records which are incorrect. Have you double checked the posterID of each record to make sure they aren't actually all equal to 1?

 

:shrug:

It was nothing to do with this query ::) Ha, sorry.

 

I had a follow up query further down the page to get the information to display. Since the query was selecting the information based on the threadID sent from the above query it had no idea which posterID to use and would just get the one that was sent from that query. The threadID's are the same in an entire thread so if bob had responded 5 posts down the page the above query would find that and carry on. The second one (due to a stupid error on my behalf) wasn't checking the posterID again and would therefore search according to the threadID that was given to it. This would mean that the information it found was the opening post in the thread that bob had posted in.

 

$get_result_query = mysql_query("SELECT
				*
			FROM
				forum_posts
			WHERE
				threadID = '$search_query_row[0]'
				AND posterID = '1'"); <!-- was missing this line.

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.