Jump to content

Search engine don't work


emilcarlo

Recommended Posts

Good evening,

 

I am a newbie when it comes to programming, and I am yet learning. With several help from this forum, and other websites, I am able to finish my very first PHP project. It worked fine, as well as the search engine. However, it is foreseen that the application will be utilizing huge amount of data which would require pagination when viewing. And so I found a tutorial from php freaks as well. However, after I integrated the codes from my web application, the search engine suddenly stopped working. It is still, when I leave the field blank, which would display all data. However, if I type down a search query on the field, it still displays all data. Can anyone help me on this? Here's my complete code:

 

<link href="add_client.css" rel="stylesheet" type="text/css">

<?PHP
include("dbconnection.php");

$query = "SELECT * FROM records";


if(isset($_POST["btnSearch"]))

{
	$query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' ORDER BY territory ASC"  ;

$result = mysql_query($query, $connection) or die(mysql_error());

} 

?>

<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="760" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="199" align="center" valign="top"><a href="login.html"><img src="invent-asia.gif" alt="" width="152" height="58" border="0" /></a>        <script type="text/javascript" src="menu.js"></script></td>
        <td width="176" align="right" valign="bottom"><a href="main.php"><img src="Home.jpg" width="104" height="20" border="0"/></a></td>
        <td width="130" align="right" valign="bottom"><img src="View.jpg" width="104" height="20" border="0"/></td>
        <td width="146" align="right" valign="bottom"><a href="add_client.php"><img src="Add.jpg" width="104" height="20" border="0"/></a></td>
        <td width="109" align="right" valign="bottom"> </td>
        </tr>

    </table></td>
  </tr>
  <tr>
    <td><table width="760" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="200" height="3"  bgcolor="#1B1C78"><img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td>
        <td width="560"  bgcolor="#0076CC"><img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td>

      </tr>
    </table></td>

  </tr>
  <tr>
    <td height="553" align="center" valign="top" bgcolor="#F3FAFE"><br />

      <form name="form" action="view_client.php" method="post">
        <br />
      <table width="351" border="0">
          <tr>
            <td width="137" align="left" valign="middle">SEARCH RECORD:</td>
            <td width="144" align="center" valign="middle"><input type="text" name="search" /></td>
            <td width="56" align="left" valign="middle"><input type="submit" name="btnSearch" value="Search" /></td>
          </tr>
        </table>
        <br />
        <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" >
          <tr>
            <th width="80" align="center" bgcolor="#E0E8F3">Territory</th>
            <th width="330" align="center" bgcolor="#E0E8F3">Employer</th>
             <th width="160" align="center" bgcolor="#E0E8F3">Name</th>
            <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th>
          </tr>
<?php

$conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('invent-asia',$conn) or trigger_error("SQL", E_USER_ERROR);


$sql = "SELECT COUNT(*) FROM records";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];


$rowsperpage = 10;

$totalpages = ceil($numrows / $rowsperpage);


if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {

   $currentpage = (int) $_GET['currentpage'];
} else {

   $currentpage = 1;
}


if ($currentpage > $totalpages) {

   $currentpage = $totalpages;
}

if ($currentpage < 1) {

   $currentpage = 1;
} 


$offset = ($currentpage - 1) * $rowsperpage;


$sql = "SELECT * FROM records LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);


if($result)
  {
  for($i=0; $i<mysql_num_rows($result); $i++)
  {
	  $id = trim(mysql_result($result, $i, "id"));
	  $territory = trim(mysql_result($result, $i, "territory"));
	  $employer = trim(mysql_result($result, $i, "employer"));
	  $first_name = trim(mysql_result($result, $i, "first_name"));
	  $last_name = trim(mysql_result($result, $i, "last_name"));
			  
  		  echo "<td>".$territory."</td>";
	  echo "<td>".$employer."</td>";
	  echo "<td>".$last_name.", ".$first_name."</td>";
	  echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a> </td>";
	  echo "</tr>";
  }
  }


$range = 3;


if ($currentpage > 1) {

   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";

   $prevpage = $currentpage - 1;

   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} 


for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {

   if (($x > 0) && ($x <= $totalpages)) {

      if ($x == $currentpage) {

         echo " [<b>$x</b>] ";

      } else {

         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } 
   }
} 
                 
       
if ($currentpage != $totalpages) {

   $nextpage = $currentpage + 1;

   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";

   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";


}

?>


  
        </table>
        <p>
<br />
        </p>
      </form>
    <p> </p></td>

  </tr>
  <tr>
    <td height="38"><table width="760" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="200" height="35" align="center"  bgcolor="#1B1C78" class=white><img src="images/topspacerblue.gif" alt="" width="1" height="3" /> <a href="disclaimer.html"><font color="#FFFFFF">Legal Disclaimer</font></a> </td>

        <td width="560" align="center"  bgcolor="#0076CC"  class=white><img src="images/topspacerlblue.gif" alt="" width="1" height="3" /> Copyright © 2006 - 2010 InventAsia Limited. All rights reserved.
</td>
      </tr>

    </table></td>
  </tr>
</table>

 

Immediate response is very well appreciated. Thank you very much ^^

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.