Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Array in PHP/MySQL
  
User name:
Password:
Reply:
 

UserPost
Mercury
Posts: 56/88
I dropped the 'IN' argument, it wouldn't really have worked with the array anyway.

I fixed it on some other way using a loop .

$game=mysql_fetch_array(mysql_query("SELECT scards FROM games WHERE id=4"));
$sc=unserialize($game[scards]);

$imgsc = array( "0", "0", "0", "0", "0", "0" );
$i=0;
while ($i < 6) {
$cimg=mysql_fetch_array(mysql_query("SELECT url FROM cards WHERE id = $sc[$i]"));
$imgsc[$i] = $cimg[url];
$i++;
}
neotransotaku
Posts: 3774/4016
To get all the fields, your query would be

SELECT * FROM table WHERE id IN (5, 28, 62, 39, 55, 72)

that query assumes your ids in your database tables is actually numbers and not strings. That same query may work for strings if you quote each number. If not, then just iterate through each id with the following query. For example, 5:

SELECT * FROM table WHERE id = 5 // int representation
SELECT * FROM table WHERE id = "5" // string representation
Mercury
Posts: 55/88
Let's say I have this array, which contains id's from a certain table in the DB:
$testarray = array( "5", "28", "62", "39", "55", "72" );


Now what I wanna do is, create a new array, using data from the database where the id's are like in the testarray. So something like this (doesn't work naturally):


$newarray[]=mysql_fetch_array(mysql_query("SELECT fields FROM table WHERE id IN ('$testarray[]')"));

So this query should store all the fields (which have the id's from the testarray) in the newarray, so I could do for example:

print "$newarray[1]";

(this array element should be the info which has id 28 in that specific table)



Dunno if this is clear, but in any case, what is the right query to do this (the one in bold)?
Acmlm's Board - I2 Archive - Programming - Array in PHP/MySQL


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.009 seconds.