Posted: Mon Jan 23, 2006 9:50 pm Post subject: Seek rows upon array
I have the PHP script with array of IDs.
I have to make output to the screen of the table data based on the array IDs i have.
I mean, mot only those IDs, but also the same order:
If there is in table:
ID data
--------
1. dog
2. cat
3. bird
4. horse
5. cow
And array is:
0:4
1:2
2:5
there has to be the output:
horse
cat
cow
filtered and ordered.
In MySQL there is no something like ORDER BY array.
Also, no possibility to JOIN array to table (or I do not know for the possibility).
I made while loop with something like:
$i=0;
$imax=mysql_num_rows("SELECT data FROM mytable");
while ($i<$imax) {
$toshow=mysql_fetch_row("SELECT data FROM mytable WHERE ID=$id[i]
LIMIT 1");
echo "$toshow ";
$i++;
}
I am emphasizing that I simplified the code here.
It works, but is there a way to do it better?
Is the WHERE fast (at the moment I am testing this with only few rows)? Is there faster fetch possibility for just one row? Is HAVING faster?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum