MySQL Forums
Forum List  »  PHP

Results before Submission
Posted by: Kevin Thirkell
Date: March 26, 2006 08:25AM

I'm hoping someone can help me out. I am trying to use a drop drop with the alphabet in it to select databases according to the first letter of their name. The code works fine except for one thing. When I load the page, before I submit anything, the entire list of databases is there already. Again, this is before I select any letters. How would I go about having this portion blank until after I make a selection?

Thanks!

below is my code

<body>
<div id="search">

<h1>Indexes &amp; Databases Search</h1>

<hr />

<div id="search_sub">

<form action="search.php" method="post">
<select name="subject">
<option value="">Choose a Subject!</option>
<option value="Business">Business</option>
<option value="Education">Education</option>
<option value="General and Interdisciplinary">General &amp; Interdisciplinary</option>
<option value="Gonvernment and Law">Government &amp; Law</option>
<option value="Health">Health</option>
<option value="Humanities">Humanities</option>
<option value="Music">Music</option>
<option value="Science">Science</option>
<option value="Social Science">Social Science</option>
</select>
<input type="submit" value="Search!">
</form>

</div>

<div id="search_abc">

<form action="search.php" method="post">
<select name="letter">
<option value="">Choose a Letter!</option>
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d">D</option>
<option value="e">E</option>
<option value="f">F</option>
<option value="g">G</option>
<option value="h">H</option>
<option value="I">I</option>
<option value="j">J</option>
<option value="k">K</option>
<option value="l">L</option>
<option value="m">M</option>
<option value="n">N</option>
<option value="o">O</option>
<option value="p">P</option>
<option value="q">Q</option>
<option value="r">R</option>
<option value="s">S</option>
<option value="t">T</option>
<option value="u">U</option>
<option value="v">V</option>
<option value="w">W</option>
<option value="x">X</option>
<option value="y">Y</option>
<option value="z">Z</option>
</select>
<input type="submit" value="Search!">
</form>

</div>

<hr />

</div>

<div id="search_results">
<?php include ("mysql-connect.php");


$subject = $_POST['subject'];
// Execute the query
$result = @mysql_query
("SELECT
data_id,
name,
subject,
description,
url
FROM
indexes
WHERE
subject= '$subject'
ORDER by
name")
or die("The database query failed.");

// Output the results

while($row = mysql_fetch_object($result))
echo
"<p>
<strong>Title:</strong><a href=\"$row->url\">$row->name</a>
<br />
<strong>Subject:</strong>$row->subject
<br />
<strong>Description:</strong> $row->description
<br />
</p> ";

$letter = $_POST['letter'];
// Execute the query
$result = @mysql_query
("SELECT
data_id,
name,
subject,
description,
url
FROM
indexes
WHERE
name LIKE '".$letter."%'
ORDER by
name")
or die("The database query failed.");

// Output the results

while($row = mysql_fetch_object($result))
echo
"<p>
<strong>Title:</strong><a href=\"$row->url\">$row->name</a>
<br />
<strong>Subject:</strong>$row->subject
<br />
<strong>Description:</strong> $row->description
<br />
</p> ";

mysql_close();
?>
</div>
</body>
</html>

Options: ReplyQuote


Subject
Written By
Posted
Results before Submission
March 26, 2006 08:25AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.