0

我正在查询作为资源输出的数据库,例如

$tracker=get_record("tracker_entries", "userid", $user, "course", $course->id, "unitid" , $unit);

输出为:

$tracker->obj;

我写了一个运行良好的循环。我正在努力解决的问题是将 $f 整数添加到资源中。即加入2个变量。

$tracker->obj.$f;

它将它们视为 2 个独立的回声,有人知道我如何加入变量以便输出

$tracker->obj1
$tracker->obj2
$tracker->obj3
$tracker->obj4

ETC

希望这是有道理的,这是我的代码

 $f=0;
 for($number=1;$number<6;$number+=1){
 for($i=0;$i<6;$i+=1){
 $f+=1;  
 $theunit = $unitx->pc.$f;
 $thetracker = $tracker->obj.$f;
 $feedback = $tracker->feedback.$f;
       if(!empty($theunit)){
          echo'<tr>
              <td class="pc" valign="top" valign="top" align="left" width="5%"><strong>'.$number.'.'.$i.'</strong> </td>
              <td valign="top" class="pc" align="left">'.$theunit.'</td>
              <td valign="top" class="pc" align="left">'.$feedback.'</td>
              <td valign="top" class="pc" align="center">'.$thetracker.'</td>
          </tr>';
      }
 }
 }

$tracker 的 var_dump(有点大)

object(stdClass)#491 (208) { ["id"]=> string(5) "11810" ["course"]=> string(3) "958" ["unitid"]=> string(4) " 1089" ["userid"]=> 字符串(4) "9659" ["obj1"]=> 字符串(2) "否" ["obj2"]=> 字符串(3) "是" ["obj3"]= > string(0) "" ["obj4"]=> string(0) "" ["obj5"]=> string(0) "" ["obj6"]=> string(0) "" ["obj7" ]=> 字符串(0) "" ["obj8"]=> 字符串(0) "" ["obj9"]=> 字符串(0) "" ["obj10"]=> 字符串(0) "" [" obj11"]=> 字符串(0) "" ["obj12"]=> 字符串(0) "" ["obj13"]=> 字符串(0) ""["obj14"]=> 字符串(0) "" ["obj15"]=> 字符串(0) "" ["obj16"]=> 字符串(0) "" ["obj17"]=> 字符串(0) "" ["obj18"]=> 字符串(0) "" ["obj19"]=> 字符串(0) "" ["obj20"]=> 字符串(0) "" ["obj21"]=> 字符串( 0) "" ["obj22"]=> 字符串(0) "" ["obj23"]=> 字符串(0) "" ["obj24"]=> 字符串(0) "" ["obj25"]=>字符串(0)“”[“obj26”]=>字符串(0)“”[“obj27”]=>字符串(0)“”[“obj28”]=>字符串(0)“”[“obj29”] => 字符串(0) "" ["obj30"]=> 字符串(0) "" ["obj31"]=> 字符串(0) "" ["obj32"]=> 字符串(0) "" ["obj33"]=> 字符串(0) "" ["obj34"]=> 字符串(0) "" ["obj35"]=> 字符串(0 ) "" ["obj36"]=> 字符串(0) "" ["obj37"]=> 字符串(0) "" ["obj38"]=> 字符串(0) "" ["obj39"]=> 字符串(0) "" ["obj40"]=> 字符串(0) "" ["obj41"]=> 字符串(0) "" ["obj42"]=> 字符串(0) "" ["obj43"]= > 字符串(0) "" ["obj44"]=> 字符串(0) "" ["obj45"]=> 字符串(0) "" ["obj46"]=> 字符串(0) "" ["obj47" ]=> 字符串(0) "" ["obj48"]=> 字符串(0) "" ["obj49"]=>字符串(0) "" ["obj50"]=> 字符串(0) "" ["obj51"]=> 字符串(0) "" ["obj52"]=> 字符串(0) "" ["obj53"] => 字符串(0) "" ["obj54"]=> 字符串(0) "" ["obj55"]=> 字符串(0) "" ["obj56"]=> 字符串(0) "" ["obj57 "]=> 字符串(0) "" ["obj58"]=> 字符串(0) "" ["obj59"]=> 字符串(0) "" ["obj60"]=> 字符串(0) "" [ "obj61"]=> 字符串(0) "" ["obj62"]=> 字符串(0) "" ["obj63"]=> 字符串(0) "" ["obj64"]=> 字符串(0) " " ["obj65"]=> 字符串(0) "" ["obj66"]=> 字符串(0) "" ["obj67"]=> 字符串(0) "" ["obj68"]=> 字符串(0) "" ["obj69"]=> 字符串(0) "" ["obj70"]=> 字符串(0) "" [" obj71"]=> 字符串(0) "" ["obj72"]=> 字符串(0) "" ["obj73"]=> 字符串(0) "" ["obj74"]=> 字符串(0) "" ["obj75"]=> 字符串(0) "" ["obj76"]=> 字符串(0) "" ["obj77"]=> 字符串(0) "" ["obj78"]=> 字符串(0) "" ["obj79"]=> 字符串(0) "" ["obj80"]=> 字符串(0) "" ["obj81"]=> 字符串(0) "" ["obj82"]=> 字符串( 0) "" ["obj83"]=> 字符串(0) "" ["obj84"]=> 字符串(0) "" ["obj85"]=> 字符串(0) "" ["obj86"]=> 字符串(0) "" ["obj87"]=> 字符串(0) "" ["obj88"]=> 字符串(0) "" ["obj89"]=> 字符串(0) "" ["obj90"]=> 字符串(0) "" ["obj91"]=> 字符串(0) "" ["obj92"]=> 字符串(0) "" ["obj93"]=> 字符串(0) "" ["obj94"]=> 字符串(0) "" ["obj95"]=> 字符串(0) "" ["obj96"]=> 字符串( 0) "" ["obj97"]=> 字符串(0) "" ["obj98"]=> 字符串(0) "" ["obj99"]=> 字符串(0) "" ["obj100"]=>字符串(0)“”[“obj101”]=>字符串(0)“”[“obj102”]=>字符串(0)“”["obj103"]=> 字符串(0) "" ["obj104"]=> 字符串(0) "" ["obj105"]=> 字符串(0) "" ["obj106"]=> 字符串(0) "" ["obj107"]=> 字符串(0) "" ["obj108"]=> 字符串(0) "" ["obj109"]=> 字符串(0) "" ["obj110"]=> 字符串( 0) "" ["obj111"]=> 字符串(0) "" ["obj112"]=> 字符串(0) "" ["obj113"]=> 字符串(0) "" ["obj114"]=>字符串(0)“”[“obj115”]=>字符串(0)“”[“obj116”]=>字符串(0)“”[“obj117”]=>字符串(0)“”[“obj118”] => 字符串(0) "" ["obj119"]=> 字符串(0) "" ["obj120"]=>字符串(0) "" ["obj121"]=> 字符串(0) "" ["obj122"]=> 字符串(0) "" ["obj123"]=> 字符串(0) "" ["obj124"] => 字符串(0) "" ["obj125"]=> 字符串(0) "" ["obj126"]=> 字符串(0) "" ["obj127"]=> 字符串(0) "" ["obj128 "]=> 字符串(0) "" ["obj129"]=> 字符串(0) "" ["obj130"]=> 字符串(0) "" ["obj131"]=> 字符串(0) "" [ "obj132"]=> 字符串(0) "" ["obj133"]=> 字符串(0) "" ["obj134"]=> 字符串(0) "" ["obj135"]=> 字符串(0) " " ["obj136"]=> 字符串(0) "" ["obj137"]=> 字符串(0) ""["obj138"]=> 字符串(0) "" ["obj139"]=> 字符串(0) "" ["obj140"]=> 字符串(0) "" ["obj141"]=> 字符串(0) "" ["obj142"]=> 字符串(0) "" ["obj143"]=> 字符串(0) "" ["obj144"]=> 字符串(0) "" ["obj145"]=> 字符串( 0) "" ["obj146"]=> 字符串(0) "" ["obj147"]=> 字符串(0) "" ["obj148"]=> 字符串(0) "" ["obj149"]=>字符串(0) "" ["obj150"]=> 字符串(0) "" ["obj151"]=> 字符串(0) "" ["obj152"]=> 字符串(0) "" ["obj153"] => 字符串(0) "" ["obj154"]=> 字符串(0) "" ["obj155"]=>字符串(0) "" ["obj156"]=> 字符串(0) "" ["obj157"]=> 字符串(0) "" ["obj158"]=> 字符串(0) "" ["obj159"] => 字符串(0) "" ["obj160"]=> 字符串(0) "" ["obj161"]=> 字符串(0) "" ["obj162"]=> 字符串(0) "" ["obj163 "]=> 字符串(0) "" ["obj164"]=> 字符串(0) "" ["obj165"]=> 字符串(0) "" ["obj166"]=> 字符串(0) "" [ "obj167"]=> 字符串(0) "" ["obj168"]=> 字符串(0) "" ["feedback1"]=> 字符串(10) "fghj" ["feedback2"]=> 字符串(10) “gfhj”[“feedback3”]=>字符串(10)“fghj”[“feedback4”]=> 字符串(10) "fghj " ["feedback5"]=> 字符串(10) "fghj" ["feedback6"]=> 字符串(10) "ghhj " ["feedback7"]=> 字符串(7) " ghj " ["feedback8"]=> string(8) "fgjh " ["feedback9"]=> string(8) "fghj" ["feedback10"]=> string(8) "fgjh " ["feedback11"]= > string(0) "" ["feedback12"]=> string(0) "" ["feedback13"]=> string(0) "" ["feedback14"]=> string(0) "" ["feedback15" ]=> string(0) "" ["feedback16"]=> string(0) "" ["feedback17"]=> string(0) "" ["feedback18"]=> string(0) "" ["反馈19"]=> 字符串(0) ""["feedback20"]=> string(0) "" ["feedback21"]=> string(0) "" ["feedback22"]=> string(0) "" ["feedback23"]=> string(8) “fghj”[“feedback24”]=>字符串(7)“ghj”[“feedback25”]=>字符串(8)“fgjh”[“feedback26”]=>字符串(8)“fghj”[“feedback27”] => string(8) "fgjh " ["comment"]=> string(0) "" ["iv"]=> string(0) "" ["grade"]=> string(0) "" [" ivgrade"]=> string(0) "" ["ivdate"]=> string(0) "" ["assessorgrade"]=> string(0) "" ["gradedate"]=> string(0) "" [“评估日期”]=> 字符串(0)“”["partofiv"]=> 字符串(1) "0" }

4

1 回答 1

0

使用标量

示例代码:

<?php
$obj = (object) 'ciao';
$obj->test1 = (object) 'test1';

$i = 1;

echo $obj->test1->scalar . PHP_EOL;

echo $obj->{'test'.$i}->scalar . PHP_EOL;

你的代码:

$theunit = $unitx->{'pc'.$f}->scalar;
$thetracker = $tracker->{'obj'.$f}->scalar;
$feedback = $tracker->{'feedback'.$f}->scalar;
于 2012-11-13T16:09:48.620 回答