dongpao9165 2015-06-30 14:05
浏览 55
已采纳

short_open_tags在while循环中显示NULL值

I have the following code that's supposed to use the oci_fetch_array() function to fill in some arguments for a new link to display on a website, however instead of

" http://website.com/reporttest.php?type=1&mode=1&dis=MECH&unit=3&rfo=20 "

it is outputting

http://website.com/reporttest.php?type=1&mode=&dis=&unit=3&rfo=20

Notice "Mode" and "Dis" are non-existent. I'm sure I'm doing something wrong in the while loop, but I'm not too familiar with PHP to figure out why exactly this is performing the way it is.

<td valign="top" width=12%>
<?
$count = 0;
?>
        <h2>None<br>
        <table border=1 align="center">

<?
while ($count < $TotalB) {
    $row = oci_fetch_array($stid, OCI_NUM);
?>
    <tr>
        <td><?= trim($row[1]) ?></td><td><a href="http://website.com/reporttest.php?type=1&mode=<?= urlencode($row[2]) ?>&dis=<?= urlencode(trim($row[1])) ?><?= $endofurl ?>"><?= trim($row[0]) ?></a></td>
    </tr>
<?
    $count = $count + trim($row[0]);
}
?>
        </table>
</td>

Output from rows:

Array ( [0] => 1 [1] => [2] => ) 
Array ( [0] => 20 [1] => ELEC [2] => ) 
Array ( [0] => 1 [1] => EPCP [2] => )
Array ( [0] => 4 [1] => EPPG [2] => )
Array ( [0] => 13 [1] => I&C [2] => )
Array ( [0] => 43 [1] => MECH [2] => )
Array ( [0] => 15 [1] => MNTS [2] => )
Array ( [0] => 1 [1] => OPS [2] => )
Array ( [0] => 7 [1] => VLVT [2] => )
Array ( [0] => 1 [1] => WHSE [2] => ) 

$TotalB defined here:

while ($row = oci_fetch_array($stid, OCI_NUM)) {
    if (trim($row[1]) == "") {$TotalB = $row[0];}
    else if (trim($row[1]) == 0) {$Total0 = $row[0];}
    else if (trim($row[1]) == 1) {$Total1 = $row[0];}
    else if (trim($row[1]) == 2) {$Total2 = $row[0];}
    else if (trim($row[1]) == 3) {$Total3 = $row[0];}
    else if (trim($row[1]) == 4) {$Total4 = $row[0];}
    else if (trim($row[1]) == 5) {$Total5 = $row[0];}
    else if (trim($row[1]) == 6) {$Total6 = $row[0];}
}

In this case print $TotalB outputs 106.

  • 写回答

1条回答 默认 最新

  • dtwbp26022 2015-06-30 14:57
    关注

    try to do away from the inline php with html and also don't forget to close that h2 tag.

    <?php
    
    $data = array(
        array ( 1, "",""),
        array ( 20, "ELEC", ""),
        Array ( 1, "EPCP", ""),
        Array ( 4, "EPPG", ""),
        Array ( 13, "I&C", ""),
        Array ( 43, "MECH", ""),
        Array ( 15, "MNTS", ""),
        Array ( 1, "OPS", ""),
        Array ( 7, "VLVT", ""),
        Array ( 1, "WHSE", "")
    );
    
    //print_r($data);
    
    $endofurl = "#"; //if you don't set this you get a notice because you call this var, i assume it's the unit=3&rfo=20 bit
    
    // mode will be empty because you set mode=$row[2] and that last key is always empty
    
    foreach ($data as $row){
    ?>
    <tr>
        <td><?= trim($row[1]) ?></td><td><a href="http:website.com/reporttest.php?type=1&mode=<?=urlencode($row[2])?>&dis=<?=urlencode(trim($row[1]))?><?=$endofurl?>"><?=trim($row[0])?></a></td>
    </tr>
    
    <?php } ?>
    

    or you can try without the inline php like so

    <?php
    while ($count < $TotalB) {
        $row = oci_fetch_array($stid, OCI_NUM);
        print'
        <tr>
            <td>'.trim($row[1]).'</td><td><a href="http:website.com/reporttest.php?type=1&mode='.urlencode($row[2]).'&dis='.urlencode(trim($row[1])) . $endofurl.'">'.trim($row[0]).'</a></td>
        </tr>';
    
        $count = $count + trim($row[0]);
    }
    print '
        </table>
    </td>';
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测