mysql DB有一个包含2列的表作为Name和values。我想要显示从min到max的值,但如果某个名称的值为零,我想跳过该值。
答案 0 :(得分:0)
由于您在一个字段中存储多个名称,然后在另一个字段中存储相应的值,因此您应该将逻辑移动到PHP。
循环遍历结果集时,每行:
//create arrays of the comma separated fields
$keys = explode(",", $row['name']);
$values = explode (",", $row['value']);
//combine them & flip since you want to use the values as keys and the keys as values
$combined = array_combine($values, $keys);
//sort by value (which has become a key)
ksort($combined);
// you should now have an array looking like:
// array(0 => "d", 1 => "c", 2 => "b", 5 => "a");
// now let's remove the 0 value
unset($combined[0]);
//debug to make sure this is what you want
print_r($combined);