Place All Resulting Rows from MySQL Query in Arrays
I have the following MySQL query:
$imgDimensions_query = "SELECT imgWidth, imgHeight FROM (
SELECT imgHeight, imgWidth FROM primary_images WHERE imgId < 10
UNION
SELECT imgHeight, imgWidth FROM secondary_images WHERE primaryId < 10) as imgDimensions";
$imgDimensions_data = mysql_query($imgDimensions_query) or die('MySql Error' . mysql_error());
I would like to place all the results in two separate arrays; One for imgWidth
, and 开发者_运维知识库one for imgHeight
.
I tried to do this using a while
loop, but I didn't know what to use inside the loop to create the arrays.
I'm going to explain what I will be doing with this information in case you think of a better method than using arrays: I will be first removing any results from imgWidth
and imgHeight
if they match an external set of values. Then I will find the maximum values of both imgWidth
and imgHeight
after said removal, and placing those two values in respective variables.
Thanks for your help.
You can use mysql_fetch_asoc() like this:
while($row = mysql_fetch_assoc($imgDimensions_data)) {
$imgWidth[] = $row['imgWidth'];
$imgHeight[] = $row['imgHeight'];
}
精彩评论