|  |  | 
          
            | Code (PHP) 
 <html>
<head>
<title>School Saving</title>
<meta http-equiv=Content-Type content="text/html; charset=tis-620">
</head>
<body>
<form  name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>">
  <table  align="center" width="700" border="1">
    <tr>
      <th>Select 
        <select name="ddlSelect" id="ddlSelect">
          <option>- Select -</option>
          <option value="StudentID" <?if($_POST["ddlSelect"]=="StudentID"){echo"selected";}?>>StudentID</option>
          <option value="Name" <?if($_POST["ddlSelect"]=="Name"){echo"selected";}?>>Name</option>
          <option value="Class" <?if($_POST["ddlSelect"]=="Class"){echo"selected";}?>>Class</option>
        </select>
        Keyword
        <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
      <input type="submit" value="Search"></th>
    </tr>
  </table>
</form>
<?
	$objConnect = mysql_connect("localhost","root","25201977") or die("Error Connect to Database");
	$objDB = mysql_select_db("school_saving");
	mysql_query("SET NAMES TIS620");
	
	// Search By Name or Email
//$strSQL = "SELECT * FROM school_student  WHERE 1 ";
 $strSQL = "SELECT 'StudentID','Name','Class','TotalAmount','Remark',
(SELECT SUM(school_deposit.Amount) FROM school_deposit WHERE school_deposit.StudentID = school_student.StudentID)- 
(SELECT SUM(school_withdraw.Amount) FROM school_withdraw WHERE school_withdraw.StudentID =school_student.StudentID) AS TotalAmount,school_student.StudentID,school_student.Name,school_student.Class,school_student.Remark
FROM  school_student
LEFT JOIN school_deposit AS school_deposit ON (school_student.StudentID = school_deposit.StudentID) 
LEFT JOIN school_withdraw AS school_withdraw ON (school_student.StudentID = school_withdraw.StudentID) 
WHERE 1 
GROUP BY school_student.StudentID,school_student.Name,school_student.Class "; 
	if($_POST["ddlSelect"] != "" and  $_POST["txtKeyword"]  != '')
	{
	  $strSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' ) ";
	}	
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
	?>
	<table  align="center" width="700" border="1">
	  <tr>
		<th width="91"> <div align="center">StudentID </div></th>
		<th width="98"> <div align="center">Name </div></th>
		<th width="198"> <div align="center">Class</div></th>
		<th width="97"> <div align="center">TotalAmount</div></th>
        <th width="97"> <div align="center">Remark</div></th>
        
	 </tr>
	<?
	while($objResult = mysql_fetch_array($objQuery))
	{
$i++;
if($i%2==0)
{
$bg = "#CCCCCC";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
		<td><div align="center"><?=$objResult["StudentID"];?></div></td>
		<td><?=$objResult["Name"];?></td>
		<td><?=$objResult["Class"];?></td>
		<td><div align="center"><?=$objResult["TotalAmount"];?></div></td>
        <td><?=$objResult["Remark"];?></td>
		
	  </tr>
	<?
	}
	?>
	</table>
	<?
	mysql_close($objConnect);
?>
</body>
</html>
 <br>
    <tr>
    <table align="center" width="700" height="10" border="0">
    <td align="center"><a  href="../admin.php"><font size="5"><font color="#F7070B">Back</font></a></td>
     </table>
 
 
 Tag : PHP, MySQL
 
 
 |  
            | 
 ประวัติการแก้ไข
 2019-08-10 14:03:08
 2019-08-10 14:50:35
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2019-08-10 13:55:09 | By :
                          wiwatklanpan | View :
                          890 | Reply :
                          4 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |