gpt4 book ai didi

php - 如何在php中显示数据 View mysql

转载 作者:行者123 更新时间:2023-11-29 23:45:55 28 4
gpt4 key购买 nike

我做了一个 View mysql和php想通过过滤器来显示操作,但是结果无法显示。这是代码该函数用于显示数据

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

此处显示数据

<?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 !';
}
?>

如何解决这个问题,我是 php 初学者。非常感谢您的帮助:)

最佳答案

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

我也会改变这个:

<?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 !';
}
?>

试试这个。

关于php - 如何在php中显示数据 View mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25953320/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com