|
|
|
ต้องการค้นหาด้วยการคลิ๊กเมาส์ใน DropDownList แล้วให้แสดงตารางข้อมูล ที่เลือก : PHP |
|
|
|
|
|
|
|
จาก Database ข้อมูลการใช้งานเครื่องพิมพ์ ซึ่งมีตาราง tb_printer และ tb_employee เ
โดยผมเองก็ได้เขียนโค๊ด PHP
Code (PHP)
<?php $_REQUEST['prnID']; ?>
<script type="text/javascript">
function chSlct(){
document.location.href = 'test-grpPrnReport.php?prnID='+(document.frmGrpPrnR.prnID.value);
}
</script>
<form action="" method="GET" enctype="multipart/form-data" name="frmGrpPrnR" id="frmGrpPrnR">
<?php
mysql_connect("localhost","root","root");
mysql_select_db("db_computer");
mysql_query("SET NAMES tis620");
$srSQL = "SELECT *
FROM tb_printer
GROUP BY prnID
ORDER BY prnID ASC";
$srre = mysql_query($srSQL) or die ("Error Query [".$srSQL."]");
echo "ค้นหา :- ";
echo "<select name=\"prnID\" id=\"prnID\" onChange=\"chSlct()\">";
echo "<option value=\"0\" selected=\"selected\">-- select Printer Name --</option>";
while($srro = mysql_fetch_array($srre)){
?>
<option value="<?php echo $srro[$prnID];?>"<?php if($srro[$prnID] == $_REQUEST['prnID']){ echo "selected";} ?>><?php echo $srro['prnName']; ?></option>
<?php } ?>
</select>
<hr>
<?php
$mySQL= "SELECT * FROM tb_printer GROUP BY prnID ORDER BY prnID ASC";
$byRES = mysql_query($mySQL);
while ($prnROW = mysql_fetch_assoc($byRES)){
$ttpgs = 0;
$ttcpys = 0;
$QUERYprn = "SELECT tb_printer.prnID, tb_printer.prnName, tb_printer.empID, tb_printer.prnID, tb_printer.pagePrint, tb_printer.pageCopy, tb_printer.pageDuplex, tb_employee.empID, tb_employee.empName,
SUM(pagePrint * pageCopy) AS Pages,
SUM(ceil(pagePrint * pageCopy/pageDuplex)) AS Papers
FROM tb_printer LEFT JOIN tb_employee
ON tb_printer.empID = tb_employee.empID
WHERE tb_printer.prnID = ". $prnROW['prnID']."
GROUP BY tb_printer.empID";
$prnRES = mysql_query($QUERYprn);
?>
<?php echo "<b>".$prnROW['prnName']; ?>
<table border=1>
<tr>
<th>empID</th>
<th>empName</th>
<th>Page of Print</th>
<th>Paper usage</th>
</tr>
<?php
while ($prnROW = mysql_fetch_assoc($prnRES)){
$ttpgs = $ttpgs + $prnROW['Pages'];
$ttcpys = $ttcpys + $prnROW['Papers'];
echo "<tr>";
echo "<td>".$prnROW['empID']."</td>
<td>". $prnROW['empName']."</td>
<td>".$prnROW['Pages']."</td>
<td>".$prnROW['Papers']."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\"><b>total : </b></td>
<td><b>".number_format($ttpgs)."</b></td>
<td><b>".number_format($ttcpys)."</b></td>";
echo "</tr>";
echo "</table><hr>";
}
mysql_free_result($prnRES);
mysql_free_result($byRES);
?>
</form>
ให้ออกผลลัพธ์แบบนี้ แต่ต้องการให้สามารถคลิ๊กเมาส์ค้นหารายชื่อเครื่องพิมพ์ (ลูกศรสีแดงครับ)
จึงขอรบกวนพี่ ๆ ช่วยแก้ไขโค๊ด หรือเพิ่มเติมโค๊ด PHP ของผมให้สามารถคลิ๊กเมาส์ใน DropDownList แล้วให้แสดงตารางข้อมูล ที่เลือกด้วยครับ ขอขอบคุณอย่างสูงมากครับ
Tag : PHP
|
|
|
|
|
|
Date :
2015-03-02 12:11:08 |
By :
pukmtec |
View :
1019 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้ไขโค๊ด เพิ่มเติมครับ
Code (PHP)
<?php $_REQUEST['prnID']; ?>
<script type="text/javascript">
function chSelect(){
document.location.href = 'test-grpPrnReport.php?prnID='+(document.frmGrpPrnR.prnID.value);
}
</script>
<form action="" method="GET" enctype="multipart/form-data" name="frmGrpPrnR" id="frmGrpPrnR">
<?php
mysql_connect("localhost","root","root");
mysql_select_db("db_computer");
mysql_query("SET NAMES tis620");
$srSQL = "SELECT *
FROM tb_printer
GROUP BY prnID
ORDER BY prnID ASC";
$srre = mysql_query($srSQL) or die ("Error Query [".$srSQL."]");
echo "ค้นหา :-";
echo "<select name=\"prnID\" id=\"prnID\" onChange=\"chSelect()\">";
echo "<option value=\"0\" selected=\"selected\">-- select Printer Name --</option>";
while($srro = mysql_fetch_array($srre)){
?>
<option value="<?php echo $srro['prnID'];?>"<?php if($srro['prnID'] == $_REQUEST['prnID']){ echo "selected";} ?>><?php echo $srro['prnName']; ?></option>
<?php } ?>
</select>
<hr>
<?php
$mySQL= "SELECT * FROM tb_printer GROUP BY prnID ORDER BY prnID ASC";
$byRES = mysql_query($mySQL);
while ($prnROW = mysql_fetch_assoc($byRES)){
$ttpgs = 0;
$ttcpys = 0;
$QUERYprn = "SELECT tb_printer.prnID, tb_printer.prnName, tb_printer.empID, tb_printer.prnID, tb_printer.pagePrint, tb_printer.pageCopy, tb_printer.pageDuplex, tb_employee.empID, tb_employee.empName,
SUM(pagePrint * pageCopy) AS Pages,
SUM(ceil(pagePrint * pageCopy/pageDuplex)) AS Papers
FROM tb_printer LEFT JOIN tb_employee
ON tb_printer.empID = tb_employee.empID
WHERE tb_printer.prnID = ". $prnROW['prnID']."
GROUP BY tb_printer.empID";
$prnRES = mysql_query($QUERYprn);
?>
<?php echo "<b>".$prnROW['prnName']; ?>
<table border=1>
<tr>
<th>empID</th>
<th>empName</th>
<th>Page of Print</th>
<th>Paper usage</th>
</tr>
<?php
while ($prnROW = mysql_fetch_assoc($prnRES)){
$ttpgs = $ttpgs + $prnROW['Pages'];
$ttcpys = $ttcpys + $prnROW['Papers'];
echo "<tr>";
echo "<td>".$prnROW['empID']."</td>
<td>". $prnROW['empName']."</td>
<td>".$prnROW['Pages']."</td>
<td>".$prnROW['Papers']."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\"><b>total : </b></td>
<td><b>".number_format($ttpgs)."</b></td>
<td><b>".number_format($ttcpys)."</b></td>";
echo "</tr>";
echo "</table><hr>";
}
mysql_free_result($prnRES);
mysql_free_result($byRES);
?>
</form>
|
|
|
|
|
Date :
2015-03-02 12:56:39 |
By :
pukmtec |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทดลองดูน่ะครับ เขียนสดไม่ได้รัน
Code (PHP)
<?php $_REQUEST['prnID']; ?>
<form action="" method="GET" enctype="multipart/form-data" name="frmGrpPrnR" id="frmGrpPrnR">
<?php
mysql_connect("localhost","root","root");
mysql_select_db("db_computer");
mysql_query("SET NAMES tis620");
$srSQL = "SELECT *
FROM tb_printer
GROUP BY prnID
ORDER BY prnID ASC";
$srre = mysql_query($srSQL) or die ("Error Query [".$srSQL."]");
echo "ค้นหา :-";
echo "<select name=\"prnID\" id=\"prnID\" onChange=\"chSelect()\" class='printer-used'>";
echo "<option value=\"0\" selected=\"selected\">-- select Printer Name --</option>";
while($srro = mysql_fetch_array($srre)){
?>
<option value="<?php echo $srro['prnID'];?>"<?php if($srro['prnID'] == $_REQUEST['prnID']){ echo "selected";} ?>><?php echo $srro['prnName']; ?></option>
<?php } ?>
</select>
<hr>
<table border=1>
<thead>
<tr>
<th>empID</th>
<th>empName</th>
<th>Page of Print</th>
<th>Paper usage</th>
</tr>
</thead>
<tbody id='tb_result'>
</tbody></table><hr>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("select.printer-used").change(function(){
$("#tb_result").load("retrieve-data.php?prnID="+$("option:selected",this).val());
});
});
</script>
retrieve-data.php
<?php
mysql_connect("localhost","root","root");
mysql_select_db("db_computer");
mysql_query("SET NAMES tis620");
if(isset($_REQUEST["prnID"]) && !empty($_REQUEST["prnID"])){
$mySQL= "SELECT * FROM tb_printer WHERE prnID='{$_REQUEST["prnID"]}' GROUP BY prnID ORDER BY prnID ASC";
$byRES = mysql_query($mySQL);
while ($prnROW = mysql_fetch_assoc($byRES)){
$ttpgs = 0;
$ttcpys = 0;
$QUERYprn = "SELECT tb_printer.prnID, tb_printer.prnName, tb_printer.empID, tb_printer.prnID, tb_printer.pagePrint, tb_printer.pageCopy, tb_printer.pageDuplex, tb_employee.empID, tb_employee.empName,
SUM(pagePrint * pageCopy) AS Pages,
SUM(ceil(pagePrint * pageCopy/pageDuplex)) AS Papers
FROM tb_printer LEFT JOIN tb_employee
ON tb_printer.empID = tb_employee.empID
WHERE tb_printer.prnID = ". $prnROW['prnID']."
GROUP BY tb_printer.empID";
$prnRES = mysql_query($QUERYprn);
echo "<b>".$prnROW['prnName'];
while ($prnROW = mysql_fetch_assoc($prnRES)){
$ttpgs = $ttpgs + $prnROW['Pages'];
$ttcpys = $ttcpys + $prnROW['Papers'];
echo "<tr>";
echo "<td>".$prnROW['empID']."</td>
<td>". $prnROW['empName']."</td>
<td>".$prnROW['Pages']."</td>
<td>".$prnROW['Papers']."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\"><b>total : </b></td>
<td><b>".number_format($ttpgs)."</b></td>
<td><b>".number_format($ttcpys)."</b></td>";
echo "</tr>";
mysql_free_result($prnRES);
mysql_free_result($byRES);
}
?>
|
|
|
|
|
Date :
2015-03-02 17:14:36 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*** ขอขอบคุณมากครับ ***
แต่โปรแกรมไม่ทำงาน ซึ่งรันไม่ออกอะไรสักอย่าง
ไฟล์แรกก็ออกแค่ DropDownList เท่านั้นเองครับ
ผมอยากให้เปิดไฟล์แล้วแสดงตารางข้อมูลทั้งหมดก่อนครับ แล้วพอเลือก จึงจะแสดงตารางที่เลือกเท่านั้นครับ
ขอขอบคุณมาก ๆ นะครับ
|
|
|
|
|
Date :
2015-03-03 12:51:58 |
By :
pukmtec |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ทราบว่ามีโค้ด jquery-lib หรือยังครับ
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
ให้ใส่ในไฟล์แรกที่มีดรอปดาวน์
Code (PHP)
<?php $_REQUEST['prnID']; ?>
<form action="" method="GET" enctype="multipart/form-data" name="frmGrpPrnR" id="frmGrpPrnR">
<?php
mysql_connect("localhost","root","root");
mysql_select_db("db_computer");
mysql_query("SET NAMES tis620");
$srSQL = "SELECT *
FROM tb_printer
GROUP BY prnID
ORDER BY prnID ASC";
$srre = mysql_query($srSQL) or die ("Error Query [".$srSQL."]");
echo "ค้นหา :-";
echo "<select name=\"prnID\" id=\"prnID\" onChange=\"chSelect()\" class='printer-used'>";
echo "<option value=\"0\" selected=\"selected\">-- select Printer Name --</option>";
while($srro = mysql_fetch_array($srre)){
?>
<option value="<?php echo $srro['prnID'];?>"<?php if($srro['prnID'] == $_REQUEST['prnID']){ echo "selected";} ?>><?php echo $srro['prnName']; ?></option>
<?php } ?>
</select>
<hr>
<table border=1>
<thead>
<tr>
<th>empID</th>
<th>empName</th>
<th>Page of Print</th>
<th>Paper usage</th>
</tr>
</thead>
<tbody id='tb_result'>
</tbody></table><hr>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#tb_result").empty().load("retrieve-data.php?prnID=all");
$("select.printer-used").change(function(){
$("#tb_result").empty().load("retrieve-data.php?prnID="+$("option:selected",this).val());
});
});
</script>
retrieve-data.php
<?php
mysql_connect("localhost","root","root");
mysql_select_db("db_computer");
mysql_query("SET NAMES tis620");
if(isset($_REQUEST["prnID"]) && !empty($_REQUEST["prnID"])){
if($_REQUEST["prnID"] == "all")
$mySQL= "SELECT * FROM tb_printer GROUP BY prnID ORDER BY prnID ASC";
else
$mySQL= "SELECT * FROM tb_printer WHERE prnID='{$_REQUEST["prnID"]}' GROUP BY prnID ORDER BY prnID ASC";
$byRES = mysql_query($mySQL);
while ($prnROW = mysql_fetch_assoc($byRES)){
$ttpgs = 0;
$ttcpys = 0;
$QUERYprn = "SELECT tb_printer.prnID, tb_printer.prnName, tb_printer.empID, tb_printer.prnID, tb_printer.pagePrint, tb_printer.pageCopy, tb_printer.pageDuplex, tb_employee.empID, tb_employee.empName,
SUM(pagePrint * pageCopy) AS Pages,
SUM(ceil(pagePrint * pageCopy/pageDuplex)) AS Papers
FROM tb_printer LEFT JOIN tb_employee
ON tb_printer.empID = tb_employee.empID
WHERE tb_printer.prnID = ". $prnROW['prnID']."
GROUP BY tb_printer.empID";
$prnRES = mysql_query($QUERYprn);
echo "<b>".$prnROW['prnName'];
while ($prnROW = mysql_fetch_assoc($prnRES)){
$ttpgs = $ttpgs + $prnROW['Pages'];
$ttcpys = $ttcpys + $prnROW['Papers'];
echo "<tr>";
echo "<td>".$prnROW['empID']."</td>
<td>". $prnROW['empName']."</td>
<td>".$prnROW['Pages']."</td>
<td>".$prnROW['Papers']."</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\"><b>total : </b></td>
<td><b>".number_format($ttpgs)."</b></td>
<td><b>".number_format($ttcpys)."</b></td>";
echo "</tr>";
mysql_free_result($prnRES);
mysql_free_result($byRES);
}
?>
|
ประวัติการแก้ไข 2015-03-03 16:09:50
|
|
|
|
Date :
2015-03-03 15:56:43 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**** ใช้งานไม่ได้ครับ ยังไม่เวิร์คครับผม ***
รบกวนพี่ๆ ด้วยครับ ขอขอบคุณมากครับ
|
|
|
|
|
Date :
2015-03-10 13:15:24 |
By :
pukmtec |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|