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());
?>

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.

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?

"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"

Thank you end result was

 

SELECT `id`, username, photo, imgtype FROM members WHERE `id` IN (".implode(',',$FLabba).") ORDER BY username ASC

 

Works fine now so it seems.

 

Oh your right Vista dont suck, i wouldn't go back to even leopard now i have vista :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.