【问题标题】:How to print more than one query result rows in html table?如何在html表中打印多个查询结果行?
【发布时间】:2014-07-06 11:44:52
【问题描述】:

我有这个代码:

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);

我的复选框在表的索引页中具有动态 ID(在 td 中),因此当用户单击复选框时,我会将这些值发布到下一页并将这些值发送到 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" } }

我正在获取这个数组,那么我该如何打印它

【问题讨论】:

  • 你能改写你的问题吗?目前还不清楚你想要什么。 重要的是,你很容易受到 sql 注入的攻击。
  • 再次检查问题,我已经编辑了解释。
  • 那么你的问题是什么?循环结果并打印表格。
  • html表格如何打印结果
  • 使用foreach

标签: php html mysql sql laravel-4


【解决方案1】:

假设你使用的是eloquent和blade

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>

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2015-01-12
    • 2021-06-08
    相关资源
    最近更新 更多