Hello all,
I built a record search and display for some information that we have in our database. The whole point of the search is so that our employees can quickly reference a document through the web browser. One of the upgrades that I am trying to do to it is create a section off to the right which shows the employee’s recently viewed record. So far, I am stumped, my attempts at logging ended up logging the search term, or the entire results list.
Any ideas?
Thanks for the help! I included the code below.
[php]
![]()
table {
border-collapse: collapse;
border: solid 1px black;
}
td {
padding: 2px 6px;
border: solid 1px black;
}
' method='post'>
Account Code or Company name:
Advanced Search
<?php
if(isset($_POST['search']))
{
$connx = mysql_connect('localhost', '*****', '*****') or die("connx");
$db = mysql_select_db('*****_*****') or die(mysql_error());
# convert to upper case, trim it, and replace spaces with "|":
$search = (ini_get('magic_quotes_gpc')) ? stripslashes($_POST['search']) :
$_POST['search'];
$search = mysql_real_escape_string($search);
$search = strtoupper(preg_replace('/[^a-zA-Z0-9-&\s]/', ' ', trim($_POST['search'])));
# create a MySQL REGEXP for the search:
$regexp = "REGEXP '[[:<:]]($search)[[:alpha:]]*[[:>:]]'";
$query = "SELECT document_name, description FROM `documents` WHERE UPPER(`document_name`) $regexp OR ".
"`document_name` $regexp";
$result = mysql_query($query) or die($query . " - " . mysql_error());
echo "
\n";
while($row = mysql_fetch_assoc($result))
{
echo "";
echo '', $row['document_name'], ' | ';
echo "
\n";
}
}
?> [/php]
Which leads to this page to display the document.
[php]
table {
border-collapse: collapse;
border: solid 1px black;
}
td {
padding: 2px 6px;
border: solid 1px black;
}
' method='post'>
Search for:
Back to Account Code Search
<?php
if(isset($_POST['search']))
{
$connx = mysql_connect('localhost', '*****', '*****') or die("connx");
$db = mysql_select_db('*****_*****') or die(mysql_error());
# convert to upper case, trim it, and replace spaces with "|":
$search = (ini_get('magic_quotes_gpc')) ? stripslashes($_POST['search']) :
$_POST['search'];
$search = mysql_real_escape_string($search);
$search = strtoupper(preg_replace('/[^a-zA-Z0-9-&\s]/', ' ', trim($_POST['search'])));
# create a MySQL REGEXP for the search:
$regexp = "REGEXP '[[:<:]]($search)[[:alpha:]]*[[:>:]]'";
$query = "SELECT document_name, description FROM `documents` WHERE UPPER(`description`) $regexp OR ".
"`document_name` $regexp";
$result = mysql_query($query) or die($query . " - " . mysql_error());
echo "<table>\n";
while($row = mysql_fetch_assoc($result))
{
echo “
”;
echo ‘’, $row[‘document_name’], ‘ | ’;
echo “
\n”;
}
}
?>
<? $hostname = "localhost"; //
$username = "*****"; //
$password = "*****"; //
$usertable = "*****"; //
$dbName = "*****_*****"; //
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?php
if(isset($_GET['docname'])) {
// Connect to MySQL
// Check docname
$docname = mysql_real_escape_string($_GET['docname']);
$query = mysql_query("SELECT document_name, description FROM `documents` WHERE `document_name`='" . $docname . "'");
if(mysql_num_rows($query) == 1) {
$doc = mysql_fetch_array($query);
echo nl2br ($doc['description']);
} else {
echo 'Document not found!';
}
}
?>[/php]