duanhai7274 2014-09-20 21:10
浏览 180

如何在php中显示数据视图mysql

I have made ​​a view mysql and php I want to display the operation through the filter, but the result could not be displayed. Here is the code this function to show data

function tampilDataRegFilter($data){
        $query=mysql_query("SELECT * from dataPendaftaran WHERE nm_mhs LIKE '%$data%'");
        $no_rows=mysql_num_rows($query);
        if($no_rows==1){
            while($row=mysql_fetch_array($query)){
                $data[]=$row;
                return $data;
            }
        }  
    }

here to show data

<?php
        //tampil berdasar filter
        if($_POST['do']=="find"){
            $arrayBayarReg=$data->tampilDataRegFilter($_POST['q']);
        }
        if(count($arrayBayarReg)){
            foreach($arrayBayarReg as $data){
                ?>
                <tr class="tabcont">
                    <td class="tabtxt" align="center"><?php echo $c=$c+1; ?>.</td>
                    <td class="tabtxt" align="center"><?php echo $data['kode_bayar'];?></td>
                    <td class="tabtxt" align="center"><?php echo $data['nm_mhs'];?></td>
                    <td class="tabtxt" align="center"><?php echo $data['tgl_bayar']; ?></td>
                    <td class="tabtxt" align="center"><?php echo $data['jumlah']; ?></td>
                    <td class="tabtxt" align="center"><?php echo $data['keterangan']; ?></td>
                </tr>
                <?php
            }
        }else{
            echo 'Not Found !';
        }
    ?>

How to solve this, i'm beginner in php. Thanks so much for helping :)

  • 写回答

1条回答 默认 最新

  • dongwu9647 2014-09-20 22:35
    关注
    function tampilDataRegFilter($data){
        $query=mysql_query("SELECT * from dataPendaftaran WHERE nm_mhs LIKE '%$data%'");
        $no_rows=mysql_num_rows($query);
        if($no_rows >= 1){ // Does this if there was more than or 1 row. Not only if there was one row
            $data = array();
            while($row=mysql_fetch_array($query)){
                $data[]=$row; // Does not return data here
            }
            return $data; // Return should only be done when all the data is in the array, which is after while loop is finished
        } else {
            return false;
        }
    }
    

    I would also switch this around:

    <?php
        //tampil berdasar filter
        if($_POST['do']=="find"){
            $arrayBayarReg=$data->tampilDataRegFilter($_POST['q']);
        }
        if($arrayBayarReg !== false){ // Returns false if no rows were found
            foreach($arrayBayarReg as $data1){ // Wouldnt overwrite the $data variable which apparently holds your data object.
                ?>
                <tr class="tabcont">
                    <td class="tabtxt" align="center"><?php echo $c=$c+1; ?>.</td>
                    <td class="tabtxt" align="center"><?php echo $data1['kode_bayar'];?></td>
                    <td class="tabtxt" align="center"><?php echo $data1['nm_mhs'];?></td>
                    <td class="tabtxt" align="center"><?php echo $data1['tgl_bayar']; ?></td>
                    <td class="tabtxt" align="center"><?php echo $data1['jumlah']; ?></td>
                    <td class="tabtxt" align="center"><?php echo $data1['keterangan']; ?></td>
                </tr>
                <?php
            }
        }else{ // Returned false, so no rows were found
            echo 'Not Found !';
        }
    ?>
    

    Try this one.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能