Jump to content

[SOLVED] MySQL search,


sager29

Recommended Posts

MySQL 5.0

I've got a database search bar on my site, and when I submit a query it shows all of the rows in the table instead of what I'm searching for.  Funny thing is, it works the first time I search, but if I back up a page and search again it shows everything? Any thoughts would be greatly appreciated.  Here some code:

 

$query="SELECT artist,title,edition,imagesize,medium,price,type,framed From listings Where artist LIKE '%$searchartist%'";
$result = mysql_query($query)
            or die ("Couldn't execute query.");

echo "<h1>Search Results</h1>";
  echo "<table width='966'>";
  echo "<tr><td colspan='8'><hr /></td></tr>";
  echo "<tr>
    <td width='124'><strong>Artist</strong></td>
    <td width='124'><strong>Title</strong></td>
    <td width='95'><strong>Type</strong></td>
    <td width='97'><strong>Edition</strong></td>
    <td width='19'><strong>Image Size</strong></td>
    <td width='92'><strong>Medium</strong></td>
    <td width='92'><strong>Framed</strong></td>
    <td width='92'><strong>Price</strong></td>

  </tr>";
  echo "<tr><td colspan='8'><hr /></td></tr>";
  
  while($row = mysql_fetch_assoc($result))
  {
     extract($row);
  
     echo "<tr>
    <td width='124'>$artist</td>
    <td width='124'>$title</td>
    <td width='95'>$type</td>
    <td width='97'>$edition</td>
    <td width='19'>$imagesize</td>
    <td width='92'>$medium</td>
    <td width='92'>$framed</td>
    <td width='92'>$price</td>

  </tr>";
          
  }
  echo "</table>\n";
?>
</body></html>

Link to comment
https://forums.phpfreaks.com/topic/78731-solved-mysql-search/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.