can somebody help me how to search data from database?coz i use dropdown to select jabatan,month and year..here the coding:

<?php
	session_start();
	include 'db_connect.php'; 
	$ID = $_SESSION['ID'];
	$PASS = $_SESSION['PASS'];
	if(($ID=="") && ($PASS==""))
	{
		echo "<script language='JavaScript'> window.location ='login_user.php';</script>"; 
	}
?>


<?php
$namajab = $_GET["nama"];
$bulan = $_GET["bulan"];
$tahun = $_GET["tahun"];
$tarikh = $_GET["tarikh"];



$jab =  $_POST["namajabatan"];

if ($jab=="1")
{
echo $jab+"dekan";
echo "<script language='JavaScript'> window.location ='archive_pejdekan.php';</script>";
}

elseif ($jab=="2")
{
echo $jab+"alam";
echo "<script language='JavaScript'> window.location ='archive_jsas.php';</script>";
}

elseif ($jab=="3")
{
echo $jab+"pengurusan";
echo "<script language='JavaScript'> window.location ='archive_jpas.php';</script>";
}

else
//echo "Tiada nilai";
?>
<?php	
	include ("db_connect.php");	
	
	$id = $_GET['ref'];

/*	$date = Date("d-m-Y");
	$test = split('-',$date);
	$value = array($test);
	//print_r($value);
	$m = $value[0][1];
	$y = $value[0][2];
	$tarikh = '-'.$m.'-'.$y;
*/	


	$viewnews =  $viewnews = "SELECT * FROM pembelian WHERE nama_jabatan = '$namajab' AND datepart(month,tarikh) = '$bulan' and  datepart(year,tarikh) = '$tahun' order by id_belian desc";
	$result = mysql_query($viewnews);
	
	$viewnews1 = "SELECT username FROM user where id = ('$ID')"; 
	$result1 = mysql_query($viewnews1);
	$num=mysql_numrows($result);
?>


<script language="javascript">
function cuba()
{
	document.bull.txtTitle.focus();
}
function error()
{
		document.returnValue=true;
		
		if(document.bull.txtTitle.value=="")
		{
			alert("Please enter the subject");
			document.bull.txtTitle.focus();
			document.returnValue=false;
		}
		else if(document.bull.txtBuletin.value=="")
		{
			alert("Please enter the bulletin");
			document.bull.txtBuletin.focus();
			document.returnValue=false;
		}
		
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SPK : Sistem Pengeluaran Kewangan</title>

<style type="text/css">
<!--
A:link {color:#4F4F96;font-size:9pt;text-decoration:none;}
A:visited {color:#4F4F96;font-size:9pt;text-decoration:none;}
A:active {color:#555555;font-size:9pt;text-decoration:none;}
A:hover {color:#555555;font-size:9pt;text-decoration:none;}
p,br,body,td,form,div {color:#555555;font-size:9pt;font-family:Verdana;}
select,textarea,input {font-size:9pt;font-family:verdana;}
.cont{line-height:140%;word-break:break-all;}
.small {font-size:8pt;font-family:tahoma,verdana;letter-spacing:0px;}
.dwarf {font-size:7pt;font-family:tahoma,verdana;letter-spacing:0px;}
.num_ver {font-family:Verdana; font-size:8pt; color:#555555}
.page_move {font-family:Verdana; font-size:7pt;}
.page_move2 {font-family:Verdana; font-size:7pt; color: #ffffff;}
.page {color:#555555;font-size:7pt;font-family:tahoma;}
.input {color:#000000; background-color:#ffffff; padding-top:3; border: 1 solid #555555; font-size:9pt;}
.input_form {font-size:8pt; font-family:tahoma; color:#555555; background-color:#ffffff; border:0 solid;}
.input_head {font-size:8pt; font-family:tahoma; color:#555555;}
.etc_form {font-family:tahoma; font-size:8pt; border:none; color:#555555; background-color:#efefef;}
.search_form {border-left-width:0; border-top-width:0; border-right-width:0; border-bottom-width:1; border-color:#cccccc; color:#555555; background-color:#FFFFFF;}
.button {font-size:9pt; font-family:verdana; border-style:ridge; background-color:#f3f3f3; border-width:1; border-top-color:#ffffff; border-right-color:#eeeeee; border-bottom-color:#eeeeee; border-left-color:#ffffff;}
.head_info {
	color: #FFFFFF;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: x-small;
	font-weight: bold;
}
.head_sub {color: #CCCCCC; font-size: x-small; font-family: Verdana, Arial, Helvetica, sans-serif; }
.dbase_data {font-size: x-small; color: #999999; }
.database {font-size: x-small; color: #999999; font-family: Verdana, Arial, Helvetica, sans-serif; }
.head_small_font {
	font-size: small;
	color: #FFFFFF;
	font: verdana;
}
.fully_read {
	font-size: small;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	color: #999999;
}
-->
</style>
<body>
<table width="800" border="0" align="center">
  <tr>
    <td colspan="3"><? include 'header.php'?></td>
  </tr>
  <tr>
    <td colspan="3"><?php echo $_SESSION['ID']?>
			( 
			<?php 
				$b=1;
				while ($rows = mysql_fetch_array($result1))
				{
					echo $rows[username]; 
					}
			?>
			)&nbsp;</span></td>
  </tr>
  <tr>
    <td colspan="3">
</span></td>
  </tr>
  <tr>
    <td width="95" valign="top"><div align="center" class="database">
      <? include 'tepi.php'?>
    </div>    </td>
    <td width="641" valign="top"><table width="30%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <th scope="row"><table width="622" border="0" bordercolor="#61b1d2">
          <tr>
            <td width="616"><img src="images/arkib_pejdekan.jpg" width="480" height="30" /></td>
          </tr> 
          <tr>
            <td class="database"><a name="top" id="top"></a>
              <table width="100%" height="403" border="0" align="center">
                <tr> </tr>
                <tr>
                  <td valign="top"><p>
                  Pejabat Dekan
                  <br />
              <table width="100%" height="403" border="0" align="center">
                <tr> </tr>
                <tr>
                  <td valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="2">
                    <tr bgcolor="#166a8f" class="head_small_font">
                      <th width="17%" scope="row"><span class="head_sub">Tajuk</span></th>
                      <th width="15%" scope="row"><span class="head_sub">Tarikh </span></th>
			          <th width="16%" scope="row"><span class="head_sub">Status</span></th>
				     
			          <th width="17%" scope="row"><span class="head_sub">Item</span></th>
			          <th width="35%" scope="row"><span class="head_sub">Tindakan</span></th>
                  </tr>
                    <tr>
                      <td><span class="database"> 
                  <?
				  	$i=0;
					while ($i < $num) {
					$id_belian=mysql_result($result,$i,"id_belian");
					$tajuk=mysql_result($result,$i,"tajuk");
					$tarikh=mysql_result($result,$i,"tarikh");
					$nama_jabatan=mysql_result($result,$i,"nama_jabatan");
					$status=mysql_result($result,$i,"status");
					$item_belian=mysql_result($result,$i,"item_belian");
					$amaun=mysql_result($result,$i,"amaun");
					//$tindakan=mysql_result($result,$i,"tindakan");
										
					?>
                        </span></span></span></td>
              </tr>
                    <tr bgcolor="#E8E8E8" class="database">
                      <td height="30"><? echo $tajuk; ?></span></td>
	      <td><div align="center"><? echo $tarikh; ?></span></div></td>
	        <td><div align="center"><? echo $status; ?></span></div></td>
			 <td><div align="center"><? echo $item_belian; ?></span></div></td>
			

	       
	        <td width="35%">
			<a href="view_belian.php?laporanid=<?php echo $id_belian?>">[Laporan]</a><a href="edit_belian.php?laporanid=<?php echo $id_belian?>">[Kemaskini]</a><a href="delete_belian.php?laporanid=<?php echo $id_belian?>">[Hapus]</a></td>
          </tr><?
			$i++;
			}
			//echo "</table>";?>
                    </table>
                  <p><?
		
		
		?>
                  
                    <br />
                  
                  <p align="right"><a href="#top">^ Top</a></td>
                </tr>
              </table><p align="right"><a href="#top"></a></td>
                </tr>
              </table></td></tr>
      </table></th>
  </tr>
</table></td>
    <td width="50" valign="top"><? include 'tepi_kanan.php'?></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center">
      <p class="style1"><? include 'footer.php'?></p>
      <p class="style4">© 2009 FPAS : SPK. Hakcipta Terpelihara .</p>
      </div></td>
  </tr>
</table>
</body>
</html>

Recommended Answers

All 2 Replies

you should use like command to search in database

try the query like that

SELECT * FROM pembelian WHERE nama_jabatan = '$namajab' AND datepart(month,tarikh) like '$bulan' and datepart(year,tarikh) like '$tahun' order by id_belian desc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.