Jump to content

Search query finds all results instead of categories


xiledweb

Recommended Posts

So, I have a database with sports related articles, and I'm having problems with users running a specific search.

The user can search by author, category and 'containing text'. Despite that, it returns all articles listed in the database.

Another, nay, several pair of eyes would be appreciated.

[code]
$authors = @mysql_query('SELECT id, name FROM author');
if (!$authors) {
  exit('<p>Unable to obtain author list from the database.</p>');
}

$cats = @mysql_query('SELECT id, name FROM category');
if (!$cats) {
  exit('<p>Unable to obtain category list from the database.</p>');
}
?>

<form action="articlelist.php" method="post">
<p>View articles satisfying the following criteria:</p>
<label>By author:
<select name="aid" size="1">
  <option selected value="">Any Author</option>
<?php
while ($author = mysql_fetch_array($authors)) {
  $aid = $author['id'];
  $aname = htmlspecialchars($author['name']);
  echo "<option value='$aid'>$aname</option>\n";
}
?>
</select></label><br />
<label>By category:
<select name="cid" size="1">
  <option selected value="">Any Category</option>
<?php
while ($cat = mysql_fetch_array($cats)) {
  $cid = $cat['id'];
  $cname = htmlspecialchars($cat['name']);
  echo "<option value='$cid'>$cname</option>\n";
}
?>
</select></label><br />
<label>Containing text: <input type="text" name="searchtext" /></label><br />
<input type="submit" value="Search" />
</form>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.