简体   繁体   English

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

[英]How to show data view mysql in php

I have made ​​a view mysql and php I want to display the operation through the filter, but the result could not be displayed. 我已经制作了一个mysql和php视图,我想通过过滤器显示操作,但是结果无法显示。 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. 如何解决这个问题,我是php的初学者。 Thanks so much for helping :) 非常感谢您的帮助:)

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. 试试这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM