我试图根据不为空的查询结果来设置一个数组。反过来,我希望以某种方式创建一个基于NON Null结果的排名。php array array()函数内的语句
SQL查询返回:
Comp1 Comp2 Comp3 Comp4 Comp5 Comp6 Comp7 Comp8 Comp9
NULL NULL 226.97 274 NULL 208 189 NULL 198.99
我的PHP:
$myarray = 'array(
if(!empty($COMP1)){
$COMP1,}
if(!empty($COMP2)){
$COMP2,}
if(!empty($COMP3)){
$COMP3,}
if(!empty($COMP4)){
$COMP4,}
if(!empty($COMP5)){
$COMP5,}
if(!empty($COMP6)){
$COMP6,}
if(!empty($COMP7)){
$COMP7,}
if(!empty($COMP8)){
$COMP8,}
if(!empty($COMP9)){
$COMP9})';
:
$COMP1 = $rankresult['Comp1'];
$COMP2 = $rankresult['Comp2'];
$COMP3 = $rankresult['Comp3'];
$COMP4 = $rankresult['Comp4'];
$COMP5 = $rankresult['Comp5'];
$COMP6 = $rankresult['Comp6'];
$COMP7 = $rankresult['Comp7'];
$COMP8 = $rankresult['Comp8'];
$COMP9 = $rankresult['Comp9'];
,因为我想只有投入变量不为空这不起作用所需输出:
$myarray = array(226.97,274,208,189,198.99)
您的数据库设计可能有缺陷。但是,为什么不使用原始数组并删除任何空值? –
我不明白。我应该发布我的MySQL查询吗? – ToddN
@ToddN col1,col2,col3其中'col'是相同的名称通常是反模式。它表示数据未正确归一化。 – Corbin