I'm trying to develop a search engine for a web site, and, I don't know much about PHP. I found two web tutorials and I tried to combine elements of both of them. What is happening is this: when I display the php page - which is designed to post to itself - (1) it prints an "else" statement that no matches were found (at the top of the page), before doing the search, and (2) after you do the search the form is displayed beneath the results...... Argh - I don't know enough to figure out why this is happening. YOu can see what it does, for the moment anyway, here:
http://guymerritt.net/new.php
Here's the code:
<?php
include_once("connect.php");
$searchquery = $_POST['searchquery'];
if(isset($_POST['searchquery']) && $_POST['searchquery'] != "")
$query="SELECT body, url, page_title FROM words WHERE page_title LIKE '%$searchquery%' OR url LIKE '%$searchquery%' OR body LIKE '%$searchquery%'";
$result=mysql_query($query);
if ($result && mysql_num_rows($result)) {
$numrows = mysql_num_rows($result);
$rowcount > 0;
print "<h2>Your search matched $numrows result(s)</h2><BR />";
print "<a href='new.php'>Return to Main</a><P>";
while ($row = mysql_fetch_assoc($result)) {
print "<table width=800 border=1 cellpadding=0 leftmargin=0 cellspacing=0>
<TD class=pad width=12% style='font-family: arial; font-size: 14px;'>$rowcount:</span> </td>";
while(list($var, $val) = each($row)) {
print "<TD style='font-family: arial; font-size: 14px;'> $val </TD>";
}
++$rowcount;
print "</table>";
}
}
else
print "No matches";
?>
<html>
<head>
</head>
<body>
<h2>Search the Exercise Tables</h2>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Search For:
<input name="searchquery" type="text" size="44" maxlength="90">
<input name="myBtn" type="submit">
<br />
</form>
<div>
<?php echo $search_output; ?>
<P>
<span style="font-family: arial; font-size 22px;">Search for <b>"DBMS"</b> to see non-working hyperlink...<br>
Search <b>"mysql"</b> to see other output values, formatting, etc......<P>
</div>
</body>
</html>
Wow - I am exhausted from messing with this. Could anyone please tell me why this is acting this way...?