Quote:
Originally Posted by Foundationflash
That bit of HTML is designed to do that - and possibly how you want to be achieving your effect. The easiest way of doing this as I see it is to:
1) Create a page results.php or similar,
2) On that page, instead of including/requiring the content, echo the results of the search in its place (not forgetting any divs that ought to ienclose the content etc)
3) Change it to <form name="search" method="post" action="results.php">
|
I think I have done what you have said correctly, in my leftmenu page I have the form:
<form name="search" method="post" action="page2.php">
Search for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="cd_title">CD Title</option>
<Option VALUE="cd_artist">CD Artist</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
Now I put the code to echo the results to my page2.php (contents)
<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
// Otherwise we connect to our Database
mysql_connect("localhost", "indiedesiuk", "pokemons") or die(mysql_error());
mysql_select_db("indiedesiuk") or die(mysql_error());
// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM cds WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['cd_title'];
echo " ";
echo $result['cd_artist'];
echo "<br>";
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
But still when I search for something the browser still sends me to
http://www.indie-design.co.uk/page2.php instead of putting the results in the page2.php which is on the main page next to the leftmenu page.
and this is my index.php which links all of my pages together
</head>
<body>
<div id="maincontainer">
<div id="topsection"><?php include("
http://www.indie-design.co.uk/topsection.html"); ?></div>
<div id="contentwrapper"><?php include("
http://www.indie-design.co.uk/page2.php"); ?></div>
<div id="leftcolumn"><?php include("
http://www.indie-design.co.uk/leftcolumn.html"); ?></div>
<div id="rightcolumn"><?php include("
http://www.indie-design.co.uk/rightcolumn.html"); ?></div>
<div id="footer"><?php include("
http://www.indie-design.co.uk/footer.html"); ?></div>
</div>
</body>
</html>