douzhouqin6223 2015-01-22 15:07
浏览 25

在echoif之后,php echo无法正常工作

I am trying to extract data from an XML file using simplexml. I am running a series of while and foreach loops to dig down to what I need.

However, I have found that after the elseif is finished I can no long display additional data to the screen (echo and print_r don't work). I have attached a code snippet for the elseif loop through the end of the end of the script. Please excuse the lousy code, I am a relatively new programmer.

elseif ($select_vars[1]==-1) {
    $sub1=0;
    $sub2=0;
    $temp_count = 1;
    $modnum=intval($select_vars[0]);
    $sub1m =  $xmls->module->{
        intval($select_vars[0])}

    ->count();
    while ($sub1 < $sub1m) {
        foreach($xmls->module->{
            $modnum}

        ->sublist1->{
            $sub1}

        as $hit2){
            $sub2m =  $xmls->module->{
                $modnum}

            ->sublist1->{
                $sub1}

            ->count();
            while ($sub2 < $sub2m) {
                foreach($xmls->module->{
                    $modnum}

                ->sublist1->{
                    $sub1}

                ->sublist2->{
                    $sub2}

                as $hit3){
                    $template_string .= $temp_count . " - " . (string)$hit3 . "<br/>";
                    $temp_count = $temp_count+1;
                    $template_list[] = (string)$hit3;
                }

                $sub2 = $sub2+1;
            }

            $sub1 = $sub1+1;
            $sub2 = 0;
        }

    }

    echo "sub1 = " . $sub1 . "<br/>";
}

echo "here <br/><br/>".$template_string;
print_r ($template_list);
$template_list = array_unique($template_list);
sort($template_list);
print_r ($template_list);

I know the loops extract the right information because I can echo anywhere in the various loops except after the esleif closing bracket.

A live copy of the code is available at: http://www.aquilasolutions.us/software/templates/pages/filter-list.php

EDIT:

The output SHOULD be 3 selects and when the top box is filled when the others are empty a series of line (up to 400+) in the format ### - ####-####-####-#### should appear.

EDIT 2: To View the error: 1. set select "Module " to be anything 2. Set select sublist 1 and sublist 2 to be empty 3. Make sure the array at the top has 3 keys (it represents a session cookie called filter-list and represents the selected items)

EDIT 3: I have tracked down the error but not been able to resolve it.

There is a fatal error in my log (Fatal error: Call to a member function count() on null) on the line:

$sub2m = $xmls->module->{$modnum}->sublist1->{$sub1}->count();

I tried putting an isnull catch in but then there was a fatal error on the isnull....

  • 写回答

1条回答 默认 最新

  • dongzhan5943 2015-01-22 15:54
    关注

    I tracked down the issue and as expected it was my own stupidity!

    I typed the wrong variable for the while ($sub2 < $sub2m) loop.

    It SHOULD have been while ($sub2 < $sub2num)

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算