Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Searching and display a result.

Posted on 2009-06-28
9
Medium Priority
?
205 Views
Last Modified: 2013-12-13
I have a page that list all of my employees in aphabeticcal order.
I would like to create a box where I could type a persons lastname and it would bring that record to the top or would hightlight the record.
Any ideas?
Thanks
Rafael
0
Comment
Question by:rcleon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 28

Expert Comment

by:gamebits
ID: 24733065
How do you get the list? Is it a text file? Or is it from a database query?
0
 

Author Comment

by:rcleon
ID: 24733070
Is from a MySQL database the query display all the records on a page.
0
 
LVL 28

Expert Comment

by:gamebits
ID: 24733075
You could have a query that will bring only the employe you are looking for.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rcleon
ID: 24733083
I think that may do the trick I will try. Thanks
0
 
LVL 28

Expert Comment

by:gamebits
ID: 24733090
If you can show your code I can help you out with this
0
 

Author Comment

by:rcleon
ID: 24733099
Great you asked for it so here it is:

<?php
session_start();
require('../dbc.php');
require('../tables.php');

$display = 10;

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

$pages = $_GET['p'];

} else {

$Query = "SELECT COUNT(EID) FROM $Table2";

$Result = mysql_query($Query);

$Row = mysql_fetch_array($Result);

$records = $Row[0];

if ($records > $display) {

$pages = ceil($records/$display);

} else { $Pages = 1;

}

} // End of p IF

// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}

// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
      $start = $_GET['s'];
} else {
      $start = 0;
}

// Determine the sort...
// Default is by registration date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd';

// Determine the sorting order:
switch ($sort) {
      case 'ln':
            $order_by = 'LastName ASC';
            break;
      case 'fn':
            $order_by = 'FirstName ASC';
            break;
      case 'rd':
            $order_by = 'EID ASC';
            break;
      default:
            $order_by = 'EID ASC';
            $sort = 'rd';
            break;
}

$Query = "SELECT *
FROM $Table1, $Table2
WHERE $Table1.CompanyNumber = '$_SESSION[CompanyNumber]' AND $Table2.CompanyNumber = '$_SESSION[CompanyNumber]'
ORDER BY $order_by
LIMIT $start,$display";

$Result = mysql_query($Query);

echo '<tr>
<td class="SubHeader"><a href="UserMaintenance.php?sort=EID">EID</a></td>
<td class="SubHeader">View</td>
<td class="SubHeader">Print</td>
<td class="SubHeader">Edit</td>
<td class="SubHeader">Delete</td>
<td class="SubHeader"><a href="UserMaintenance.php?sort=ln">Last Name</a></td>
<td class="SubHeader"><a href="UserMaintenance.php?sort=fn">First Name</a></td>
<td class="SubHeader">Username</td>
<td class="SubHeader">&nbsp;</td>
</tr>';

$bg = '#eeeeee';

while ($EmpInfo=mysql_fetch_object($Result)) {

$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');



echo '<tr bgcolor="' . $bg . '">

<td valign="top" class="GeneralText">' . $EmpInfo->EID . '</td>';

echo '<td>
<form action="../home.php" id="View" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="hidden" name="submitted" value="' . TRUE . '">
<input type="submit" name="submit" value="View"></form>
</td>';

echo '<td>';

if( $EmpInfo->PrintFormat == "S") {
echo '<form action="../pfv/stdindex.php" id="Print" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Print"></form>';
}

if($EmpInfo->PrintFormat == "N") {
echo '<form action="../pfv/newsindex.php" id="Print" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Print"></form>';
}

if($EmpInfo->PrintFormat == "B") {
echo '<form action="../pfv/bookindex.php" id="Print" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Print"></form>';
}

echo '</td>';

echo '<td>
<form action="EditEmployee.php" id="Edit" method="post">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Edit"></form>
</td>

<td>
<form action="Delete.php" id="Delete" method="post">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="submit" value="Delete"></form>
</td>

<td valign="top" class="GeneralText">' . $EmpInfo->LastName . '</td>
<td valign="top" class="GeneralText">' . $EmpInfo->FirstName . '</td>
<td valign="top" class="GeneralText">' . $EmpInfo->Username . '</td>
<td valign="top" class="GeneralText"><img src="../images/Spacer.gif" alt="" width="50" height="1" border="0"></td>
</tr>';


} // End While loop

echo '<tr><td colspan="7"><img src="images/Spacer.gif" alt="" width="1" height="20" border="0"></td></tr>

</table>';

mysql_free_result($Result);
mysql_close($dbc);

// Make the links to other pages, if necessary.
if ($pages > 1) {

      echo '<br /><div class="pagination">';
      $current_page = ($start/$display) + 1;

      // If it's not the first page, make a Previous button:
      if ($current_page != 1) {
            echo '<a href="UserMaintenance.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
      }

      // Make all the numbered pages:
      for ($i = 1; $i <= $pages; $i++) {
            if ($i != $current_page) {
                  echo '<a href="UserMaintenance.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a>';
            } else {
                  echo '<span class=current>' . $i . ' ' . '</span>' ;
            }
      } // End of FOR loop.

      // If it's not the last page, make a Next button:
      if ($current_page != $pages) {
            echo '<a href="UserMaintenance.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
      }

      echo '</div>'; // Close the paragraph.

} // End of links section.

?>
0
 
LVL 28

Accepted Solution

by:
gamebits earned 2000 total points
ID: 24733272
Ok, few things

1) I do not have all the files so i cannot test my code, there might be adjustment to be made as far as field name for the query etc.

2) Make sure you have a backup copy of the file prior of trying this one

3) Since I cannot reproduce the look of your page without having the info from your database I had to guess where to put the box

4) In my query I used a LIKE statement which will allow a forgiving search, (you can search with part of the last name the query will return every name who contains the sequence of letter in the search)

5) here is the modified code
<?php
session_start();
//require('../dbc.php');
//require('../tables.php');
 
$display = 10;
 
if (isset($_GET['p']) && is_numeric($_GET['p'])) {
 
$pages = $_GET['p'];
 
} else {
 
$Query = "SELECT COUNT(EID) FROM $Table2";
 
$Result = mysql_query($Query);
 
$Row = mysql_fetch_array($Result);
 
$records = $Row[0];
 
if ($records > $display) {
 
$pages = ceil($records/$display);
 
} else { $Pages = 1;
 
}
 
} // End of p IF
 
// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
 
// Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])) {
      $start = $_GET['s'];
} else {
      $start = 0;
}
 
// Determine the sort...
// Default is by registration date.
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd';
 
// Determine the sorting order:
switch ($sort) {
      case 'ln':
            $order_by = 'LastName ASC';
            break;
      case 'fn':
            $order_by = 'FirstName ASC';
            break;
      case 'rd':
            $order_by = 'EID ASC';
            break;
      default:
            $order_by = 'EID ASC';
            $sort = 'rd';
            break;
}
 //Gamebits
if($_POST['empname'] != ''){
  
  $Query = "SELECT * FROM $Table1, $Table2
            WHERE LastName LIKE '%lastname%'";}else{
//Gamebits
$Query = "SELECT *
FROM $Table1, $Table2
WHERE $Table1.CompanyNumber = '$_SESSION[CompanyNumber]' AND $Table2.CompanyNumber = '$_SESSION[CompanyNumber]'
ORDER BY $order_by
LIMIT $start,$display";
            }
$Result = mysql_query($Query);
     //Gamebits
echo "<tr><td><form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">
               <input type=\"text\" name=\"empname\" size=\"20\">
               <input type=\"submit\" name=\"submit\" value=\"Search\">
               </form></td></tr>";
         //Gamebits
echo '
<tr>
<td class="SubHeader"><a href="UserMaintenance.php?sort=EID">EID</a></td>
<td class="SubHeader">View</td>
<td class="SubHeader">Print</td>
<td class="SubHeader">Edit</td>
<td class="SubHeader">Delete</td>
<td class="SubHeader"><a href="UserMaintenance.php?sort=ln">Last Name</a></td>
<td class="SubHeader"><a href="UserMaintenance.php?sort=fn">First Name</a></td>
<td class="SubHeader">Username</td>
<td class="SubHeader">&nbsp;</td>
</tr>';
 
$bg = '#eeeeee';
 
while ($EmpInfo=mysql_fetch_object($Result)) {
 
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');
 
 
 
echo '<tr bgcolor="' . $bg . '">
 
<td valign="top" class="GeneralText">' . $EmpInfo->EID . '</td>';
 
echo '<td>
<form action="../home.php" id="View" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="hidden" name="submitted" value="' . TRUE . '">
<input type="submit" name="submit" value="View"></form>
</td>';
 
echo '<td>';
 
if( $EmpInfo->PrintFormat == "S") {
echo '<form action="../pfv/stdindex.php" id="Print" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Print"></form>';
}
 
if($EmpInfo->PrintFormat == "N") {
echo '<form action="../pfv/newsindex.php" id="Print" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Print"></form>';
}
 
if($EmpInfo->PrintFormat == "B") {
echo '<form action="../pfv/bookindex.php" id="Print" method="post" target="_blank">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Print"></form>';
}
 
echo '</td>';
 
echo '<td>
<form action="EditEmployee.php" id="Edit" method="post">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="admin" value="Edit"></form>
</td>
 
<td>
<form action="Delete.php" id="Delete" method="post">
<input type="hidden" name="UID" value="' . $EmpInfo->UID . '">
<input type="hidden" name="EID" value="' . $EmpInfo->EID . '">
<input type="submit" name="submit" value="Delete"></form>
</td>
 
<td valign="top" class="GeneralText">' . $EmpInfo->LastName . '</td>
<td valign="top" class="GeneralText">' . $EmpInfo->FirstName . '</td>
<td valign="top" class="GeneralText">' . $EmpInfo->Username . '</td>
<td valign="top" class="GeneralText"><img src="../images/Spacer.gif" alt="" width="50" height="1" border="0"></td>
</tr>';
 
 
} // End While loop
 
echo '<tr><td colspan="7"><img src="images/Spacer.gif" alt="" width="1" height="20" border="0"></td></tr>
 
</table>';
 
mysql_free_result($Result);
mysql_close($dbc);
 
// Make the links to other pages, if necessary.
if ($pages > 1) {
 
      echo '<br /><div class="pagination">';
      $current_page = ($start/$display) + 1;
 
      // If it's not the first page, make a Previous button:
      if ($current_page != 1) {
            echo '<a href="UserMaintenance.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
      }
 
      // Make all the numbered pages:
      for ($i = 1; $i <= $pages; $i++) {
            if ($i != $current_page) {
                  echo '<a href="UserMaintenance.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a>';
            } else {
                  echo '<span class=current>' . $i . ' ' . '</span>' ;
            }
      } // End of FOR loop.
 
      // If it's not the last page, make a Next button:
      if ($current_page != $pages) {
            echo '<a href="UserMaintenance.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
      }
 
      echo '</div>'; // Close the paragraph.
 
} // End of links section.
 
?>

Open in new window

0
 

Author Comment

by:rcleon
ID: 24929765
gamebits, sorry I took so long to get back to the question but had couple of emergencies,
Thanks for your response with a little actualy very little twicking it worked great just what I was looking for.

Thanks for all your time and effort

Rafael
0
 

Author Closing Comment

by:rcleon
ID: 31597761
Thanks soooooooooooooooo much for all your help
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question