如何在html表中打印多个查询结果行?

时间:2014-05-18 12:51:09

标签: php html mysql sql laravel-4

我有这段代码:

static function mcontent($chkbox){
   $count = count($chkbox);
   foreach ($chkbox as $value){
       $count = count($value);
       for($i=0;$i>$count;$i++) {
       $sql = "SELECT * FROM `radio_city` where chkid in (\"$value[$i]\")";

   } }
return DB::select($sql);

我的复选框在表(在td中)的索引页面中有动态ID,因此当用户单击复选框时,我将这些值发布到下一页并将这些值发送到mysql查询,如上所示(至选择那些取决于用户选择的两行以上,所以现在我将这些值发送到查询以从数据库中获取行并需要在html表中打印。

array(8) { ["city"]=> string(1) "8" ["duration"]=> string(1) "0" ["frequency"]=> string(1) "0" ["hours"]=> string(1) "0" ["days"]=> string(1) "0" ["checkbox"]=> array(2) { [2]=> string(5) "bang2" [3]=> string(5) "bang3" } ["TotlCost"]=> string(6) "Rs 0/-" ["email"]=> string(25) "prasanna.mundas@gmail.com" } array(1) { [0]=> object(stdClass)#552 (9) { ["state"]=> string(9) "Karnataka" ["city"]=> string(9) "Bangalore" ["station"]=> string(15) "Radio Fever 104" ["language"]=> string(5) "Hindi" ["reach"]=> string(5) "7.90%" ["rate"]=> string(3) "500" ["rank"]=> string(3) "181" ["idnum"]=> int(8) ["chkid"]=> string(5) "bang3" } }

我正在获取此数组,以便如何打印此

1 个答案:

答案 0 :(得分:0)

假设您正在使用雄辩和刀片

myFunction(){
    $someArray =  radioCity::whereIn('chkid',$chkbox);
    return View::make('some.page',compact('someArray'));
}

查看

<table>
    <thead>
       <tr>
           <th>City</th>
           <th>Duration</th>
           <th>yada yada</th>
       </tr>
     </thead>
     <tbody>
       @foreach($someArray as $row)
         <tr>
           <td>{{ $row['city'] }} </td>
           <td>{{ $row['duration'] }} </td>
           <td>{{ $row['yadayada'] }} </td>
         </tr>
       @endforeach
     </tbody>
</table>