Posted by Bob Stearns on 11/22/05 09:00
julian_m wrote:
> let's say I've an array of articles's id
>
> $arr_art_id=(1, 551, 2015, 6 .......n )
>
> what option is better (1 or 2), in order to achieve better performance?
>
> (pseudo code)
> 1)
> for i=0 to array count{
> select * from articles where articles.id=$arr_art_id[i]
> mysqlquery($sql)
> //do whatever i have to do
> }
>
>
> 2)
>
> $or ='';
> for i=0 to array count{
> $sql.= $or . 'articles.id='. $arr_art_id[i];
> $or ='or';
> }
>
> $sql = 'select * from articles where' .$sql
>
>
> //do whatever i have to do
>
> tia
>
> regards - julian maisano
>
Better than either:
$sql = 'select * from articles where articles.id in ($arr_art_id)';
mysqlquery($sql);
//do whatever i have to do
[Back to original message]
|