MySQL查询返回不可能的值

时间:2017-10-23 16:52:54

标签: php mysql

不确定我是否疯了,这就是我的数据库的样子:

+--------+-----+-----+-----+-------+-------+--------+------+-------+-----------+
| itemid | sku | upc | ean | title | style | gender | size | color | modelcode |
+--------+-----+-----+-----+-------+-------+--------+------+-------+-----------+
|   21   |00021| xxx | xxx | Bolt  | Tank  | Girls  | Small| Blue  | 60        |
+--------+-----+-----+-----+-------+-------+--------+------+-------+-----------+

这是我运行的查询:

$query = "SELECT itemid,
upc,
sku,
ean,
title,
style,
gender,
color,
modelcode,
price,
quantity,
pagelink,
imagelinksmall,
description

from clothing where modelcode = $modelcode";

并且正在运行var_dump($rows[0]['size']);我得到的值"XX-Small"应该只是"Small"

每个modelcode有多个大小,并且其间有很多if / else语句。这是整个脚本:

$query = "SELECT itemid,
upc,
sku,
ean,
title,
style,
size,
gender,
color,
modelcode,
price,
quantity,
pagelink,
imagelinksmall,
description

from clothing where modelcode = $modelcode"; 

// This function is static for 5 different sizes, from X-Small to X-Large. If there is an XX-Small available, the script will only go to Large. If there's an XX-Large, the script will stop where
// it normally does, which is at X-Large.

function resultToArrays($result) {            // This Function declares an array as $rows, loops through each row while there's any left, and stores it into the array
  $rows = array();                            // Declares $rows as an array
  while ($row = $result -> fetch_assoc()) {   // The while loop that iterates through any and all pulled rows
    $rows[] = $row;                           // Stores the information
  }
  return $rows;
};

$result = $con->query($query);
$rows = resultToArrays($result);

$color = $rows[0]['color'];
$style = $rows[0]['style'];
$description = $rows[0]['description'];
$imagelinksmall = $rows[0]['imagelinksmall'];
$gender = $rows[0]['gender'];

if (count($rows) == 7 && $rows[0]['size'] = "XX-Small") {
    $xxSmall = $rows[0];
    $xSmall = $rows[1];
    $small = $rows[2];
    $medium = $rows[3];
    $large = $rows[4];
    $xLarge = $rows[5];
    $xxLarge = $rows[6];
    $configField = "<td>sku=$color $style $xxSmall[size],apparel_size=$xxSmall[size]|sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]|sku=$color $style $xLarge[size],apparel_size=$xLarge[size]|sku=$color $style $xxLarge[size],apparel_size=$xxLarge[size]</td>";
} else if (count($rows) == 6 && $rows[0]['size'] = "X-Small") {
    $xSmall = $rows[0];
    $small = $rows[1];
    $medium = $rows[2];
    $large = $rows[3];
    $xLarge = $rows[4];
    $xxLarge = $rows[5];
    $configField = "<td>sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]|sku=$color $style $xLarge[size],apparel_size=$xLarge[size]|sku=$color $style $xxLarge[size],apparel_size=$xxLarge[size]</td>";
} else if (count($rows) == 6 && $rows[0]['size'] = "XX-Small") {
    $xxSmall = $rows[0];
    $xSmall = $rows[1];
    $small = $rows[2];
    $medium = $rows[3];
    $large = $rows[4];
    $xLarge = $rows[5];
    $configField = "<td>sku=$color $style $xxSmall[size],apparel_size=$xxSmall[size]|sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]|sku=$color $style $xLarge[size],apparel_size=$xLarge[size]</td>";
} else if (count($rows) == 5 && $rows[0]['size'] = "Small") {
    $small = $rows[0];
    $medium = $rows[1];
    $large = $rows[2];
    $xLarge = $rows[3];
    $xxLarge = $rows[4];
    $configField = "<td>sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]|sku=$color $style $xLarge[size],apparel_size=$xLarge[size]|sku=$color $style $xxLarge[size],apparel_size=$xxLarge[size]</td>";
} else if (count($rows) == 5 && $rows[0]['size'] = "X-Small") {
    $xSmall = $rows[0];
    $small = $rows[1];
    $medium = $rows[2];
    $large = $rows[3];
    $xLarge = $rows[4];
    $configField = "<td>sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]|sku=$color $style $xLarge[size],apparel_size=$xLarge[size]</td>";
} else if (count($rows) == 5 && $rows[0]['size'] = "XX-Small") {
    $xxSmall = $rows[0];
    $xSmall = $rows[1];
    $small = $rows[2];
    $medium = $rows[3];
    $large = $rows[4];
    $configField = "<td>sku=$color $style $xxSmall[size],apparel_size=$xxSmall[size]|sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]</td>";
} else if (count($rows) == 4 && $rows[0]['size'] = "XX-Small") {
    $xxSmall = $rows[0];
    $xSmall = $rows[1];
    $small = $rows[2];
    $medium = $rows[3];
    $configField = "<td>sku=$color $style $xxSmall[size],apparel_size=$xxSmall[size]|sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]</td>";
} else if (count($rows) == 4 && $rows[0]['size'] = "X-Small") {
    $xSmall = $rows[0];
    $small = $rows[1];
    $medium = $rows[2];
    $large = $rows[3];
    $configField = "<td>sku=$color $style $xSmall[size],apparel_size=$xSmall[size]|sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]</td>";
} else if (count($rows) == 4 && $rows[0]['size'] = "Small") {
    $small = $rows[0];
    $medium = $rows[1];
    $large = $rows[2];
    $xLarge = $rows[3];
    $configField = "<td>sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]|sku=$color $style $xLarge[size],apparel_size=$xLarge[size]</td>";
} else {
    $small = $rows[0];
    $medium = $rows[1];
    $large = $rows[2];
    $configField = "<td>sku=$color $style $small[size],apparel_size=$small[size]|sku=$color $style $medium[size],apparel_size=$medium[size]|sku=$color $style $large[size],apparel_size=$large[size]</td>";
};

我已经对所有内容进行了三次检查,而且我现在真的很茫然。

0 个答案:

没有答案