how to search data from database to display on web page based on dropdown list

Reply

Join Date: Apr 2009
Posts: 1
Reputation: zurainah is an unknown quantity at this point 
Solved Threads: 0
zurainah zurainah is offline Offline
Newbie Poster

how to search data from database to display on web page based on dropdown list

 
0
  #1
Apr 9th, 2009
can somebody help me how to search data from database?coz i use dropdown to select jabatan,month and year..here the coding:

  1. <?php
  2. session_start();
  3. include 'db_connect.php';
  4. $ID = $_SESSION['ID'];
  5. $PASS = $_SESSION['PASS'];
  6. if(($ID=="") && ($PASS==""))
  7. {
  8. echo "<script language='JavaScript'> window.location ='login_user.php';</script>";
  9. }
  10. ?>
  11.  
  12.  
  13. <?php
  14. $namajab = $_GET["nama"];
  15. $bulan = $_GET["bulan"];
  16. $tahun = $_GET["tahun"];
  17. $tarikh = $_GET["tarikh"];
  18.  
  19.  
  20.  
  21. $jab = $_POST["namajabatan"];
  22.  
  23. if ($jab=="1")
  24. {
  25. echo $jab+"dekan";
  26. echo "<script language='JavaScript'> window.location ='archive_pejdekan.php';</script>";
  27. }
  28.  
  29. elseif ($jab=="2")
  30. {
  31. echo $jab+"alam";
  32. echo "<script language='JavaScript'> window.location ='archive_jsas.php';</script>";
  33. }
  34.  
  35. elseif ($jab=="3")
  36. {
  37. echo $jab+"pengurusan";
  38. echo "<script language='JavaScript'> window.location ='archive_jpas.php';</script>";
  39. }
  40.  
  41. else
  42. //echo "Tiada nilai";
  43. ?>
  44. <?php
  45. include ("db_connect.php");
  46.  
  47. $id = $_GET['ref'];
  48.  
  49. /* $date = Date("d-m-Y");
  50. $test = split('-',$date);
  51. $value = array($test);
  52. //print_r($value);
  53. $m = $value[0][1];
  54. $y = $value[0][2];
  55. $tarikh = '-'.$m.'-'.$y;
  56. */
  57.  
  58.  
  59. $viewnews = $viewnews = "SELECT * FROM pembelian WHERE nama_jabatan = '$namajab' AND datepart(month,tarikh) = '$bulan' and datepart(year,tarikh) = '$tahun' order by id_belian desc";
  60. $result = mysql_query($viewnews);
  61.  
  62. $viewnews1 = "SELECT username FROM user where id = ('$ID')";
  63. $result1 = mysql_query($viewnews1);
  64. $num=mysql_numrows($result);
  65. ?>
  66.  
  67.  
  68. <script language="javascript">
  69. function cuba()
  70. {
  71. document.bull.txtTitle.focus();
  72. }
  73. function error()
  74. {
  75. document.returnValue=true;
  76.  
  77. if(document.bull.txtTitle.value=="")
  78. {
  79. alert("Please enter the subject");
  80. document.bull.txtTitle.focus();
  81. document.returnValue=false;
  82. }
  83. else if(document.bull.txtBuletin.value=="")
  84. {
  85. alert("Please enter the bulletin");
  86. document.bull.txtBuletin.focus();
  87. document.returnValue=false;
  88. }
  89.  
  90. }
  91. </script>
  92. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  93. <html xmlns="http://www.w3.org/1999/xhtml">
  94. <head>
  95.  
  96. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  97. <title>SPK : Sistem Pengeluaran Kewangan</title>
  98.  
  99. <style type="text/css">
  100. <!--
  101. A:link {color:#4F4F96;font-size:9pt;text-decoration:none;}
  102. A:visited {color:#4F4F96;font-size:9pt;text-decoration:none;}
  103. A:active {color:#555555;font-size:9pt;text-decoration:none;}
  104. A:hover {color:#555555;font-size:9pt;text-decoration:none;}
  105. p,br,body,td,form,div {color:#555555;font-size:9pt;font-family:Verdana;}
  106. select,textarea,input {font-size:9pt;font-family:verdana;}
  107. .cont{line-height:140%;word-break:break-all;}
  108. .small {font-size:8pt;font-family:tahoma,verdana;letter-spacing:0px;}
  109. .dwarf {font-size:7pt;font-family:tahoma,verdana;letter-spacing:0px;}
  110. .num_ver {font-family:Verdana; font-size:8pt; color:#555555}
  111. .page_move {font-family:Verdana; font-size:7pt;}
  112. .page_move2 {font-family:Verdana; font-size:7pt; color: #ffffff;}
  113. .page {color:#555555;font-size:7pt;font-family:tahoma;}
  114. .input {color:#000000; background-color:#ffffff; padding-top:3; border: 1 solid #555555; font-size:9pt;}
  115. .input_form {font-size:8pt; font-family:tahoma; color:#555555; background-color:#ffffff; border:0 solid;}
  116. .input_head {font-size:8pt; font-family:tahoma; color:#555555;}
  117. .etc_form {font-family:tahoma; font-size:8pt; border:none; color:#555555; background-color:#efefef;}
  118. .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;}
  119. .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;}
  120. .head_info {
  121. color: #FFFFFF;
  122. font-family: Verdana, Arial, Helvetica, sans-serif;
  123. font-size: x-small;
  124. font-weight: bold;
  125. }
  126. .head_sub {color: #CCCCCC; font-size: x-small; font-family: Verdana, Arial, Helvetica, sans-serif; }
  127. .dbase_data {font-size: x-small; color: #999999; }
  128. .database {font-size: x-small; color: #999999; font-family: Verdana, Arial, Helvetica, sans-serif; }
  129. .head_small_font {
  130. font-size: small;
  131. color: #FFFFFF;
  132. font: verdana;
  133. }
  134. .fully_read {
  135. font-size: small;
  136. font-family: Verdana, Arial, Helvetica, sans-serif;
  137. color: #999999;
  138. }
  139. -->
  140. </style>
  141. <body>
  142. <table width="800" border="0" align="center">
  143. <tr>
  144. <td colspan="3"><? include 'header.php'?></td>
  145. </tr>
  146. <tr>
  147. <td colspan="3"><?php echo $_SESSION['ID']?>
  148. (
  149. <?php
  150. $b=1;
  151. while ($rows = mysql_fetch_array($result1))
  152. {
  153. echo $rows[username];
  154. }
  155. ?>
  156. )&nbsp;</span></td>
  157. </tr>
  158. <tr>
  159. <td colspan="3">
  160. </span></td>
  161. </tr>
  162. <tr>
  163. <td width="95" valign="top"><div align="center" class="database">
  164. <? include 'tepi.php'?>
  165. </div> </td>
  166. <td width="641" valign="top"><table width="30%" border="0" cellspacing="2" cellpadding="2">
  167. <tr>
  168. <th scope="row"><table width="622" border="0" bordercolor="#61b1d2">
  169. <tr>
  170. <td width="616"><img src="images/arkib_pejdekan.jpg" width="480" height="30" /></td>
  171. </tr>
  172. <tr>
  173. <td class="database"><a name="top" id="top"></a>
  174. <table width="100%" height="403" border="0" align="center">
  175. <tr> </tr>
  176. <tr>
  177. <td valign="top"><p>
  178. Pejabat Dekan
  179. <br />
  180. <table width="100%" height="403" border="0" align="center">
  181. <tr> </tr>
  182. <tr>
  183. <td valign="top"><table width="100%" border="0" cellspacing="2" cellpadding="2">
  184. <tr bgcolor="#166a8f" class="head_small_font">
  185. <th width="17%" scope="row"><span class="head_sub">Tajuk</span></th>
  186. <th width="15%" scope="row"><span class="head_sub">Tarikh </span></th>
  187. <th width="16%" scope="row"><span class="head_sub">Status</span></th>
  188.  
  189. <th width="17%" scope="row"><span class="head_sub">Item</span></th>
  190. <th width="35%" scope="row"><span class="head_sub">Tindakan</span></th>
  191. </tr>
  192. <tr>
  193. <td><span class="database"
  194. <?
  195. $i=0;
  196. while ($i < $num) {
  197. $id_belian=mysql_result($result,$i,"id_belian");
  198. $tajuk=mysql_result($result,$i,"tajuk");
  199. $tarikh=mysql_result($result,$i,"tarikh");
  200. $nama_jabatan=mysql_result($result,$i,"nama_jabatan");
  201. $status=mysql_result($result,$i,"status");
  202. $item_belian=mysql_result($result,$i,"item_belian");
  203. $amaun=mysql_result($result,$i,"amaun");
  204. //$tindakan=mysql_result($result,$i,"tindakan");
  205.  
  206. ?>
  207. </span></span></span></td>
  208. </tr>
  209. <tr bgcolor="#E8E8E8" class="database">
  210. <td height="30"><? echo $tajuk; ?></span></td>
  211. <td><div align="center"><? echo $tarikh; ?></span></div></td>
  212. <td><div align="center"><? echo $status; ?></span></div></td>
  213. <td><div align="center"><? echo $item_belian; ?></span></div></td>
  214.  
  215.  
  216.  
  217. <td width="35%">
  218. <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>
  219. </tr><?
  220. $i++;
  221. }
  222. //echo "</table>";?>
  223. </table>
  224. <p><?
  225.  
  226.  
  227. ?>
  228.  
  229. <br />
  230.  
  231. <p align="right"><a href="#top">^ Top</a></td>
  232. </tr>
  233. </table><p align="right"><a href="#top"></a></td>
  234. </tr>
  235. </table></td></tr>
  236. </table></th>
  237. </tr>
  238. </table></td>
  239. <td width="50" valign="top"><? include 'tepi_kanan.php'?></td>
  240. </tr>
  241. <tr>
  242. <td colspan="3"><div align="center">
  243. <p class="style1"><? include 'footer.php'?></p>
  244. <p class="style4"2009 FPAS : SPK. Hakcipta Terpelihara .</p>
  245. </div></td>
  246. </tr>
  247. </table>
  248. </body>
  249. </html>
Last edited by Ezzaral; Apr 9th, 2009 at 2:01 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 254
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: how to search data from database to display on web page based on dropdown list

 
0
  #2
Apr 10th, 2009
you should use like command to search in database
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 254
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: how to search data from database to display on web page based on dropdown list

 
0
  #3
Apr 10th, 2009
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
Last edited by BzzBee; Apr 10th, 2009 at 8:10 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC