i have a field date(masa) with format ([0-9]{2})/([0-9]{2})/([0-9]{4})...want build a search engine based on this date format..
this is my coding for searching..
<td height="20" valign="top"><div align="center">
<form name="form1" method="post" action="dapatcapaimohon.php">
<table width="57%" border="0">
<tr>
<td height="9"><div align="center"><strong>Laporan Permohonan Pada</strong></div></td>
</tr>
<tr>
<td height="1"> </td>
</tr>
<tr>
<td height="1"><div align="center"><strong>Bulan </strong>
<select name="carianbulan">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">06</option>
</select>
<strong>Tahun
<input name="cariantahun" type="text" size="2">
</strong></div></td>
</tr>
<tr>
<td height="1"> </td>
</tr>
<tr>
<td height="-1"><div align="center">
<input type="submit" name="Submit" value="Capai">
</div></td>
</tr>
<tr>
<td height="1"> </td>
</tr>
<tr>
<td height="-1"><div align="center"> </div></td>
</tr>
<tr>
<td height="1"> </td>
</tr>
</table>
</form>
</div></td>
And this is my coding for searching result....
<td>
<?php
// create short variables names
$carianbulan = $HTTP_POST_VARS['carianbulan'];
$cariantahun = $HTTP_POST_VARS['cariantahun'];
$carianbulan = trim ($carianbulan);
$cariantahun = trim ($cariantahun);
if (!$carianbulan || !$cariantahun)
{
echo '<tr><td class="centre"><strong>Anda tidak memasukkan maklumat carian.<br>
Sila kembali dan cuba sekali lagi!</strong></td></tr>';
exit;
}
$carianbulan = addslashes($carianbulan);
$cariantahun = addslashes($cariantahun);
include 'dbase.php';
$a = 0;
$query = "SELECT * FROM mohon WHERE masa ='([0-9]{2})-('%".$carianbulan."%')-('%".$cariantahun."%')'";
$result = mysql_db_query($dbname,$query);
$num_results = mysql_num_rows($result);
echo '<tr><td class="centre"><strong>Jumlah rekod yang ditemui: '.$num_results.'</strong></td></tr>';
?><br>
<table width="86%" border="1" align="center" cellpadding="3" cellspacing="0">
<br>
<tr class="centre">
<td width="7%" class="table"><strong>Bil</strong></td>
<td width="36%" class="table"><strong>Nama </strong></td>
<td width="16%" class="table"><strong>Bahagian</strong></td>
<td width="26%" class="table"><strong>Tujuan</strong></td>
<td width="15%" class="table"><strong>Bil Pengguna</strong></td>
</tr>
<?
while($row = mysql_fetch_array($result))
{
$a++;
$nama = $row["nama"];
$bahagian = $row["bahagian"];
$tujuan = $row["tujuan"];
$bil = $row["bil"];
?>
<tr class="senarai">
<td class="centre"><? echo $a; ?></td>
<td><a href="pilih.php?view=<? echo $nama ?>"><? echo $nama; ?></a></td>
<td class="centre"><? echo $bahagian; ?></td>
<td class="centre"><? echo $tujuan; ?></td>
<td class="centre"><? echo $bil; ?></td>
</tr>
<? } ?>
</table></td>
there's no error in it but the result for the search failed to display even though the data is in the database..... 🙂