Here is my problem:
I have a mySQL database with 3 columns (for simplicities sake - there are other irrelevant columns) and 3000 rows of data (again for simplicities sake), on which I am executing the loop below:
$iCount = count($item_ids);
for($i=0;$i<$iCount;$i++){
$q="SELECT item_id, value_date FROM $dataTable WHERE value_date >= $sDate AND value_date <= $eDate AND price_disc <> 'NA' AND item_id = '".$item_ids[$i]."' ORDER BY value_date";
$q=$myConn->query($q);
if($q->num_rows>0){
$x=0;
while($row=$q->fetch_assoc()){
$iData[$i][0]=$row['item_id'];
$iData[$i][1][$x]=$row['value_date'];
$x++;
}
$q->free();
}
set_time_limit(30);
}
to fill a PHP array (as you can see).
The above code is working, though VERY slowly as it currently iterates approx 3000 times (one for each item_id).
I am looking for a way to gather the data into an array in the same format as it is currently (with the item_id being array[$i][0] and the value_date being array[$i][1][$x]), but in a single query rather than 3000.
Note: I do not want to have to re-organize the database unless completely necessary.
I am sure there is a simple way to do this. Thanks in advance.
EDIT: I know that I can use IN('.join(item_ids).') to make it into one query string, I just don't know how to get the result in an array with the same dimensions as the one I have described.