在我的编辑表单中,我想显示我可以选择谁将执行用户请求的员工姓名,但是当我尝试显示它时,它只显示了员工的一个名字,而我把while语句用于获取数据,它显示了2个具有不同下拉列表值的编辑表单(第一个编辑表单显示了我的员工A,第二个显示了我的员工B),如何显示员工A和员工B在同一下拉列表中以相同的形式命名?这是我目前的代码:
Mat I = imread("test.png", CV_LOAD_IMAGE_GRAYSCALE);
I.convertTo(B, CV_8U);
findContours(B, contour_vec, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
答案 0 :(得分:0)
您只获取结果的第一个数据集。使用fetchAll()
$data = $resultkaryawan->fetchAll()
您的循环位置错误。我想你只想迭代$ data来填补你的数据。所以你应该这样做:
<select>
<option value=''>>-----SELECT-----<</option>
<?php while($data = $resultkaryawan->fetchAll()){ ?>
<option value=''><?= $data['nm_karyawan'] ?></option>
<?php } ?>
</select>
然而,你必须构造你的代码否则输出html。但这是一个放置循环的例子。
要输出你的HTML,你可以这样做:
$page_number = $_GET['page'];
$dbdit = new PDO('mysql:host=localhost;dbname=laundry','root','');
$results = $dbdit->prepare("SELECT COUNT(*) FROM konsumen");
$results->execute();
$get_total_rows = $results->fetch();
$results = $dbdit->prepare("SELECT * FROM konsumen ORDER BY kode_pemesanan ASC LIMIT $page_number");
$resultkaryawan = $dbdit->prepare("SELECT * FROM karyawan");
$results->execute();
$resultkaryawan->execute();
$row = $results->fetch();
?>
<table align='center' >
<form method='POST' action='save.php' align='center'>
<tr>
<td>Kode Pemesanan</td>
<td>:</td>
<td><input type='text' name='kode_pemesanan' value='<?= $row['kode_pemesanan'] ?>' class='inputnomor' disabled></td>
<tr>
<td>Atas Nama</td>
<td>:</td>
<td><input type='text' name='atas_nama' value='<?= $row['atas_nama'] ?>' class='inputnomor' disabled></td>
<tr>
<td>Jumlah Baju</td>
<td>:</td>
<td><input name='jumlahBaju' type='number' class='inputpemesanan' id='jumlahbaju' value='<?= $row['jmlhbaju'] ?>' min='0' onChange='calcBaju()'> Rp.3500,00-/pcs <input name='totalBaju' type='number' class ='total' id='totalbaju' value='".$row['jmlhbaju'] * 3500 . "' min='0' disabled onChange='calcBaju()'></td>
<tr>
<td>Jumlah Celana</td>
<td>:</td>
<td><input name='jumlahCelana' type='number' class='inputpemesanan' id='jumlahCelana' value='".$row['jmlhcelana']."' min='0' onChange='calcCelana()'> Rp.2500,00-/pcs <input name='totalCelana' type='number' class ='total' id='totalcelana' value='".$row['jmlhcelana'] * 2500 . "' min='0' disabled onChange='calcCelana()'></td>
<tr>
<td>Jumlah Jaket</td>
<td>:</td>
<td><input name='jumlahJaket' type='number' class='inputpemesanan' id='jumlahjaket' value='".$row['jmlhjaket']."' min='0' onChange='calcJaket()'> Rp.6500,00-/pcs <input name='totalJaket' type='number' class ='total' id='totaljaket' value='".$row['jmlhjaket'] * 6500 . "' min='0' disabled onChange='calcJaket()'></td>
<tr>
<td>Jumlah Jas</td>
<td>:</td>
<td><input name='jumlahJas' type='number' class='inputpemesanan' id='jumlahjas' value='".$row['jmlhjas']."' min='0' onChange='calcJas()'> Rp.8500,00-/pcs <input name='totalJas' type='number' class ='total' id='totaljas' value='".$row['jmlhjas'] * 8500 . "' min='0' disabled onChange='calcJas()'></td>
<tr>
<td>Jumlah Dress</td>
<td>:</td>
<td><input name='jumlahDress' type='number' class='inputpemesanan' id='jumlahdress' value='".$row['jmlhdress']."' min='0' onChange='calcDress()'> Rp.7500,00-/pcs <input name='totalDress' type='number' class ='total' id='totaldress' value='".$row['jmlhdress'] * 7500 . "' min='0' disabled onChange='calcDress()'></td>
<tr>
<td>Status Pesanan</td>
<td>:</td>
<td><input type='radio' name='status_pesanan' value='sedangproses'>Sedang di Proses<input type='radio' name='status_pesanan' value='sudahselesai'>Sudah Selesai
</td>
<tr>
<td>Pengurus Pesanan</td>
<td>:</td>
<td>
<select>
<option value=''>>-----SELECT-----<</option>
<?php while($data = $resultkaryawan->fetchAll()){ ?>
<option value=''><?= $data['nm_karyawan'] ?></option>
<?php } ?>
</select>
</td>
</form>
</table>
它有相当多的HTML,所以我懒得用$ row-values填写你的php,你必须自己动手。基本上你必须切换
".$row['jmlhcelana']."
到
<?= $row['jmlhcelana'] ?>
答案 1 :(得分:-1)
试试这个
while($row = $results->fetch()) {
print_r($row);
}