Acmlm's Board - I2 Archive - Programming - Array in PHP/MySQL
User | Post |
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)? |
|