Jump to content

SQL "IN" statement help required please


gerkintrigg

Recommended Posts

Hello. I'd like to work out how to make the following work:

 

$sp_sql=mysql_query("select DISTINCT poked from pokes where poked IN(".$poked_by.") && poke_deleted='n' && !poked IN(".$double_pokes.")");
		while ($sp= mysql_fetch_array($sp_sql)){
		$single_pokes.=','.$sp['poked'];
		}

This is for this website... it's nothing rude...http://www.pigorpoke.com

 

I'm trying to select all from an array where the results' poked value are NOT in a string of numbers.

 

 

Link to comment
Share on other sites

Nope, no errors @ this stage, jesirose, but it's still not working ;o)

 

I also tried

$sp_sql=mysql_query("select DISTINCT poked from pokes where poked IN($poked_by) && poke_deleted='n' && !poked IN($double_pokes)") or die(mysql_error());
		while ($sp= mysql_fetch_array($sp_sql) or die (mysql_error())){
		$single_pokes.=','.$sp['poked'];
		}

but this displays nothing...

 

Perhaps I need a left join?

 

i thought the code you wrote would work, and even tried it before trying to get some help on the forum. *shrug* weird innit?

Link to comment
Share on other sites

Do this:

print "select DISTINCT poked from pokes where poked IN($poked_by) && poke_deleted='n' && !poked IN($double_pokes)"

What does it show? If the values aren't what you're expecting, there's the problem.

$poked_by and $double_pokes need to be comma separated strings like 1,2,3,4

Link to comment
Share on other sites

Use NOT IN.

SELECT
DISTINCT poked
FROM
pokes
WHERE
poked IN($poked_by) && poke_deleted='n' && poked NOT IN($double_pokes)

 

You could also use PHP to remove the entries in $poked_by that are also in $double_pokes to avoid having to use the NOT IN.

Link to comment
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.