Jump to content

[SOLVED] Just a quick one


laPistola

Recommended Posts

You can use the reserved word IN, never tried it with a SELECT but it should work all the same. All you need to do is implode the array and use a comma as the separator.

 

<?php
$array = array("1","3","26");

mysql_query("SELECT * FROM table WHERE id IN ('" . implode(",",$array) . "')") or die("Error: ".mysql_error());
?>

Link to comment
Share on other sites

Yeah, should work. No need to make it an array. And declaring it like that probably wouldn't make it an array anyway. You should be exploding it where the comma is the delimiter.

 

But as for your question, no you don't need to implode, and you don't need to make it an array.

Link to comment
Share on other sites

OK this didn't work properly,

 

i have only come to try and get more then one row out if it did i see its only seeing the first number.

 

so i changed it to this to test

 

"SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN ('6,8') ORDER BY username ASC"

 

6 and 8 are in the database and when i echo mysql_num_rows it shows up at 1 any ideas?

Link to comment
Share on other sites

"SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN ('6,8') ORDER BY username ASC"

 

 

Your format is wrong.  You're currently passing 1 thing to IN.

 

 

"SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN (6,8) ORDER BY username ASC"

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.