Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果设置不起作用?_Php_If Statement_Isset - Fatal编程技术网

Php 如果设置不起作用?

Php 如果设置不起作用?,php,if-statement,isset,Php,If Statement,Isset,分贝 在PHP中 row1 (type column=apple), (stage column=1) row2 (type column=orange), (stage column=NULL) 最终输出显示为“苹果,阶段1”“橙色,阶段” 如果Stage为空,我如何在没有Stage这个词的情况下显示“Apple,Stage 1”“Orange” 第2行(橙色)以分贝表示。更改此行 $query = mysql_query("SELECT * from fruits"); $row = m

分贝

在PHP中

row1 (type column=apple), (stage column=1)
row2 (type column=orange), (stage column=NULL)
最终输出显示为“苹果,阶段1”“橙色,阶段”

如果Stage为空,我如何在没有Stage这个词的情况下显示“Apple,Stage 1”“Orange” 第2行(橙色)以分贝表示。

更改此行

$query = mysql_query("SELECT * from fruits");

$row = mysql_fetch_array($query);

    $num = mysql_num_rows($query);
    $i=0;
    $storeMyData = array();
    while($row = mysql_fetch_array($query))
    {
        if(isset($row['type'])){
            $type = "-" . $row['type'];
        } else {
            $type = NULL;
        }

        if(isset($row['stage'])){
            $stage = "STAGE " . $row['stage'];
        } else {
            $stage = NULL;
        }
        $fruit = implode (", ", array_filter(array($type, $stage)));

    // This will show 2 rows of data
    $storeMyData[] = $fruit;  

    // store current data in array
    $i++;
    }

    /* this will echo your storedData of loop */
    foreach($storeMyData as $prevData)

    /* or join the data using string concatenation */
    $allFinalData2 = "";

    /* this will echo your storedData of loop */
    foreach($storeMyData as $prevData)
    {
        $allFinalData2 = $allFinalData2.$prevData ;  // keep on concatenating
    }

    echo $allFinalData2;
另外,不需要在循环中调用mysql_查询,使用它可以避免混淆

while($row = mysql_fetch_array($query))

我已经将$row设置为mysql\u fetch\u array($query);已经,但仍然不起作用:(传递给mysql\u fetch\u数组的变量必须与代码的其余部分匹配。在顶部有mysql\u num\u行($query),因此您应该将$query变量传递给您的mysql\u fetch\u数组。发布更新的代码列表,以便我们可以仔细检查第二行查询,这很好。但是我需要同时显示这两行
while($row = mysql_fetch_array($query))
$type = "-" . $row['type'];
$stage = "STAGE " . $row['stage'];