Page 1 of 1

Search using Multiple data.

Posted: Thu Jun 10, 2004 10:25 pm
by crypdude
This is my html will look like :

Code: Select all

<?php
<p>&nbsp;</p>
<center>
<?php
print "<form name action="search_result.php" method="post">
	  <table class="tablehead" height="162" cellSpacing="1" cellPadding="2" border="0" class="tablehead">
		<tbody>
		  <tr class="rowA" vAlign="center">
			<td vAlign="center" colSpan="2" height="1"><strong>Search Foreigner(s)</strong></td>
			<td height="207" rowspan="10" class="rowB"><img src="images/search_icon.gif" border="0" width="156" height="206"></td>
		  </tr>
		  <tr class="rowB">
			<td height="25">Passport Number</td>
			<td height="25"><input class="textfield" name="passno" size="20"></td>
			</tr>
		  <tr class="rowB">
			<td height="25">First Name</td>
			<td height="25"><input class="textfield" name="fname" size="20"></td>
		  </tr>
		  <tr class="rowB">
			<td height="25">Surname</td>
			<td height="25"><input class="textfield" name="sname" size="20"></td>
		  </tr>
		  <tr class="rowB">
			<td height="26">Country of Origin</td>
			<td height="26">";
include "countries.php"; 
print "
			</td>
		  </tr>
		  <tr class="rowB">
			<td height="26">Month of Entry</td>
			<td height="26"> ";
include "months.php"; 
			
print "	<input class="textfield" name="year" size="4" maxlength="4">eg. 2004</td>
		  </tr>
		  <tr class="rowB">
			<td height="26">Visa Used for Entry</td>
			<td height="26">
				<select size="1" name="vused">
				<option value="Visit Pass (Social)">Visit Pass (Social)</option>
				<option value="Visit Pass (Temporary Employment)">Visit Pass (Temporary Employment)</option>
				<option value="Visit Pass (Profesional)">Visit Pass (Profesional)</option>
				<option value="Employment Pass">Employment Pass</option>
				<option value="Dependent Pass">Dependent Pass</option>
				<option value="Student Pass">Student Pass</option>
				</select>
			
			</td>
		  </tr>
		  <tr class="rowB">
			<td height="26">Visa Status</td>
			<td height="26">
				<select size="1" name="visa_status">
				<option value="Without Visa">Without Visa</option>
				<option value="Visa with Reference">Visa with Reference</option>
				<option value="Visa without Reference">Visa without Reference</option>
				</select>			
			</td>
		  </tr>
		  <tr class="rowB">
			<td height="26">Visa Types</td>
			<td height="26">
				<select size="1" name="visa_types">
				<option value="Single Entry Visa">Single Entry Visa</option>
				<option value="Multiple Entry Visa">Multiple Entry Visa</option>
				<option value="Transit Visa">Transit Visa</option>
				</select>			
			</td>
		  </tr>
		  <tr class="rowB">
			<td align="right" height="27"></td>
			<td align="right" height="27">
				<input class="submit" type="button" value="Save It" name="save">&nbsp;
				<input class="submit" type="submit" value="Search" name="search"></td>
		  </tr>
		</tbody>
	  </table>
	</form>";
?>
</center><!-- End Main Mody -->
?>
And this is the sql engine.(result should come here!)


Code: Select all

<?php
<?php
include "config.php";
include "security.php";
$PageTitle = "Search Result";
include "header.php";
echo "<h1> $PageTitle </h1>";

if ($user[permission] == "0" || $user[permission] == "2") {

}// end of if student = data entry
?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
   <tr>
       <td class="hrz_line2"></td>
   </tr>
   <tr>
       <td valign="middle" height="20"><strong>Option:</strong> <a href="search_e.php">Search Menu</a> | <a href="under_c.php">Print</a></td>
   </tr>
   <tr>
       <td class="hrz_line2"></td>
   </tr>	
</table>


<?php
switch ($i) {
case 0:
   echo "i equals 0";
   break;
case 1:
   echo "i equals 1";
   break;
case 2:
   echo "i equals 2";
   break;
}

//Count Attempts and if statement

if ($passno){
	$a = "passport = '$passno'";
}
if ($fname){
	$b= "f_name = '$fname'";
}
if ($sname){
	$c= "l_name = '$sname'";
}
//if ($sname{
//	$c= "l_name ='$sname'";
//}
if ($countries){
	$d= "country_origin = '$countries'";
}
if ($vused){
	$e= "type_of_passes = '$vused'";
}
if ($visa_status){
	$f= "visa_status = '$visa_status'";
}
if ($visa_types){
	$g= "visa_types = '$visa_types'";
}

//$result = mysql_query("SELECT COUNT(*) AS count FROM register where country_origin = '$countries' and type_of_passes = '$vused' and visa_status = '$visa_status' and visa_types = '$visa_types'");

$result = mysql_query("SELECT COUNT(*) AS count FROM register where '$b'");
$row = mysql_fetch_array($result);

//$sql ="SELECT * FROM register where country_origin = '$countries' and type_of_passes = '$vused' and visa_status = '$visa_status' and visa_types = '$visa_types' ORDER BY id";
$sql ="SELECT * FROM register where '$b'";

//$result23 = mysql_query("SELECT * FROM register where passport = '$passno' or f_name = '$fname' or l_name ='$sname' or country_origin = '$countries' or type_of_passes = '$vused' or visa_status = '$visa_status' or visa_types = '$visa_types' ORDER BY id");


print "<p><strong>Total Foreigner Found:</strong> $row[count]</p>\n";
print "<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tablehead">
          <tr>
              <td class="rowA" align="center"><strong>Action</strong></td>
              <td class="rowA"><strong>ID</strong></td>
              <td class="rowA"><strong>Title Name</strong></td>
              <td class="rowA"><strong>First Name</strong></td>
              <td class="rowA"><strong>Last Name</strong></td>
              <td class="rowA"><strong>Gender</strong></td>
              <td class="rowA"><strong>Birth Date</strong></td>
              <td class="rowA"><strong>IC/Passport No</strong></td>
              <td class="rowA"><strong>Authority of Issue</strong></td>
              <td class="rowA"><strong>Country</strong></td>
              <td class="rowA"><strong>Visa Status</strong></td>
              <td class="rowA"><strong>Visa Types</strong></td>
              <td class="rowA"><strong>Issued Date</strong></td>
              <td class="rowA"><strong>Expiring Date</strong></td>
              <td class="rowA"><strong>Type of Passes</strong></td>
              <td class="rowA"><strong>Sponsor</strong></td>
              <td class="rowA"><strong>Place of Residence</strong></td>
              <td class="rowA"><strong>Account Created</strong></td>
              <td class="rowA"><strong>Last Access</strong></td>
          </tr>\n";




$result2 = mysql_query($sql) or die(mysql_error());
while ($row2 = mysql_fetch_array($result2)) {

      //Find Last Access
      $dd = substr($row2[last_access],6,2);
      $mm = substr($row2[last_access],4,2);
      $yyy = substr($row2[last_access],0,4);
      $HH = substr($row2[last_access],8,2);
      $MM = substr($row2[last_access],10,2);
      $SS = substr($row2[last_access],12,2);
      
      $access = "$mm-$dd-$yyy $HH:$MM:$SS";

      //Find Created Date
      $dd = substr($row2[created],6,2);
      $mm = substr($row2[created],4,2);
      $yyy = substr($row2[created],0,4);
      $HH = substr($row2[created],8,2);
      $MM = substr($row2[created],10,2);
      $SS = substr($row2[created],12,2);

      $created = "$mm-$dd-$yyy $HH:$MM:$SS";

      print "<tr>
                 <td class="rowB" align="center" valign="top"><a href="user_basic_edit.php?user_id=$row2[user_id]" onclick="NewWindow(this.href,'client_edit','450','480','no');return false">Edit</a> | <a href="user_basic_delete.php?user_id=$row2[user_id]" onclick="NewWindow(this.href,'user_delete','300','170','no');return false">Delete</a></td>
                 <td class="rowB" valign="top">$row2[id]</td>
                 <td class="rowB" valign="top">$row2[t_name]</td>
                 <td class="rowB" valign="top">$row2[f_name]</td>
                 <td class="rowB" valign="top">$row2[l_name]</td>
                 <td class="rowB" valign="top">$row2[gender]</td>
                 <td class="rowB" valign="top">$row2[birthdate]</td>
                 <td class="rowB" valign="top">$row2[pass_ic_no]</td>
                 <td class="rowB" valign="top">$row2[authority_of_issues]</td>
                 <td class="rowB" valign="top">$row2[country_origin]</td>
                 <td class="rowB" valign="top">$row2[visa_status]</td>
                 <td class="rowB" valign="top">$row2[visa_types]</td>
                 <td class="rowB" valign="top">$row2[issued_date]</td>
                 <td class="rowB" valign="top">$row2[expiring_date]</td>
                 <td class="rowB" valign="top">$row2[type_of_passes]</td>
                 <td class="rowB" valign="top">$row2[sponsor]</td>
                 <td class="rowB" valign="top">$row2[place_of_residence]</td>
                 <td class="rowB" valign="top">$created</td>
                 <td class="rowB" valign="top">$access</td>
             </tr>\n";

}


print "</table>\n";
include "footer.php";
?>


?>
Then i got problems when i want to throw sql statement on it. What should i do.. Multiple data to search something. I'm really stuck here. Somebody pls help me..911..plss...!

Posted: Thu Jun 10, 2004 11:42 pm
by feyd
uhhhhhhhhhh..... I'm not up for reading a small novel of code, so I'll throw this out: I'm guessing you don't have register_globals on (and you shouldn't), so you need to fix these if's

Code: Select all

if ($passno){ 
   $a = "passport = '$passno'"; 
} 
if ($fname){ 
   $b= "f_name = '$fname'"; 
} 
if ($sname){ 
   $c= "l_name = '$sname'"; 
} 
//if ($sname{ 
//   $c= "l_name ='$sname'"; 
//} 
if ($countries){ 
   $d= "country_origin = '$countries'"; 
} 
if ($vused){ 
   $e= "type_of_passes = '$vused'"; 
} 
if ($visa_status){ 
   $f= "visa_status = '$visa_status'"; 
} 
if ($visa_types){ 
   $g= "visa_types = '$visa_types'"; 
}
and please use quoted strings for associative array entries

Code: Select all

//Find Last Access 
      $dd = substr($row2[last_access],6,2); 
      $mm = substr($row2[last_access],4,2); 
      $yyy = substr($row2[last_access],0,4); 
      $HH = substr($row2[last_access],8,2); 
      $MM = substr($row2[last_access],10,2); 
      $SS = substr($row2[last_access],12,2); 
      
      $access = "$mm-$dd-$yyy $HH:$MM:$SS"; 

      //Find Created Date 
      $dd = substr($row2[created],6,2); 
      $mm = substr($row2[created],4,2); 
      $yyy = substr($row2[created],0,4); 
      $HH = substr($row2[created],8,2); 
      $MM = substr($row2[created],10,2); 
      $SS = substr($row2[created],12,2);
(there are others)