I’m a newbie to php and mysql and am creating a simple search application as a learning exercise (not for development). There are three steps in the process:

STEP 1. SEARCH FORM (input searchterm and document type with GET method)

STEP 2. SEARCH RESULTS (displays list of document numbers as links from which one document can be selected and displayed in step 3)

STEP 3. DOCUMENT TEXT (full document text that can run several pages)

The code is in one php file (search.php) and does work crudely. Here are two issues that I need some help with at this point in the project:

ISSUE 1. When I click on the document number links in the SEARCH RESULTS list, it passes the $FullDocumentID through a GET method to the DOCUMENTS TEXT section by reloading the page and erasing the data in the SEARCH RESULTS list. I would like the list data to remain visible (without having to resort to the browser Back button to reload the search results).

ISSUE 2. When the page loads for the first time (before any search or search results are available), there is no $FullDocumentID for the third step, therefore an error message is displayed:

“Warning: mysql_fetch_array() expects parameter 1 to be resource, Boolean …”

Of course this warning goes away once a link in the SEARCH RESULTS is clicked and the page is reloaded with the document ID in the URL – the GET allows the passing of the ID for the final db query that loads the document text.

I would like for the warning statement not to be visible during the first two steps of the search and display process. Just a blank space or perhaps a default document could be loaded when the application starts?

Here is the page code:

<HTML>
<HEAD>
</HEAD>
<BODY>

<h1>Search Form</h1>

<form method="get" action="search.php?go" id="searchform">
Search Term <input type="text" id="" name="searchterm">
Document Type <select name="doctype">
<option value="1">Text</option>
<option value="3">Background</option>
<option value="2">Reports</option>
<option value="4">Index</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>

<h1>Search Results</h1>

<?
$searchterm=$_GET['searchterm'];
$doctype=$_GET['doctype'];
?>

<p>for: <span style="font-size: 14px; font-weight: bold; color: red;"><? echo $searchterm; ?></span> </p>

<?
mysql_connect("xx", "xx", "xx") or die( mysql_error());
mysql_select_db("xx") or die(mysql_error());

$result1 = mysql_query(
"SELECT
SectionText,
FullDocumentID,
ReadingNo,
SectionTypeID,
CONCAT(ReadingNo, '-', SequenceNo) AS full_doc_number
FROM Full_Documents
WHERE SectionText LIKE '%$searchterm%' AND SectionTypeID = '$doctype'
Order By FullDocumentID");

$num_records = mysql_num_rows($result1);
?>

<p>documents found: <span style="font-size: 14px; font-weight: bold; color: red;"><? echo $num_records; ?></span></p>

<?
while ($row = mysql_fetch_array($result1, MYSQL_ASSOC)) {
$full_doc_number=$row ['full_doc_number'];
$FullDocumentID=$row ['FullDocumentID'];
echo '<a href="\ecr/search.php?ID=' . $FullDocumentID . '">' . $full_doc_number . '</a><br />';
}
?>

<h1>Document Display</h1>

<?
$result2 = mysql_query(
"SELECT
SectionText,
FullDocumentID
FROM Full_Documents
WHERE FullDocumentID = " . $_GET['ID']);;

echo "<table border='0' width='800px'>
<tr class=\"style3\">
";
while($row = mysql_fetch_array($result2))
{
echo "<tr class=\"style2\">";
echo "<td style=\"width: 800px;\"><p>" . preg_replace("/\r\n|\r|\n/", "</p><p>", $row['SectionText']) . "</p></td>";
echo "</tr>";
}
echo "</table>";
?>

</BODY>
</HTML>

Thanks in advance for any help that can be provided in solving these issues (or any other suggestions/input that you wish to provide at this point in the process). - Dave