duanfu7840 2014-12-23 06:30
浏览 44
已采纳

从另一个脚本调用变量

im trying assign values to my variables in ascript by calling a function and variables from another script, but currently im getting errors saying

Undefined property: stdClass::$Boys in

Undefined property: stdClass::$Girls in

im calling a function in a script called report.php from my script

report.php

public function projectReport($ID){
    $get_con = $this->getConnection();
    $result = mysql_query($query, $get_con);
    $rep = new stdClass();
    if(false !== $result){
        $multis = array();
        while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
            $count = new stdClass();
            $count->Boys = (int)$row['males'];
            $count->Girls = (int)$row['females'];
            $multis[] = $count;

        }
        $rep->multiples = $multis;

    }
return $rep;
    }

function body of my script

$report = new Report();
$log = $report->projectReport($ID);
if($log != false){
    $Boys = $log->Boys;
    $Girls = $log->Girls;
    print_r($Boys);
    print_r($Girls);
}

return $log;
  • 写回答

1条回答 默认 最新

  • dpgbh20688 2014-12-23 07:44
    关注

    your $log can never be false so you don't need to check that. Alhtough multiples attribute might be missing.

    Try this:

    $report = new Report();
    $log = $report->projectReport($ID);
    if(property_exists($log, 'multiples')){  //check if multiples attribute exists
        foreach ($log->multiples as $m)      //walk through every multiples record
        {
            $Boys = $m->Boys;                //get Boys and Girls attributes values and print them
            $Girls = $m->Girls;
            print_r($Boys);
            print_r($Girls);
        }
    }
    

    I'm pretty sure that's not what you wanna achieve, but that how it should work based on what you've got so far.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。