Jump to content

MySQL search


sager29

Recommended Posts

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>";
  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 "<tr><td colspan='8'><hr /></td></tr>\n";
  }
  echo "</table>\n";
?>
</body></html>

Link to comment
Share on other sites

variables are not stored from page to page on PHP, you have to use sessions or place the values in cookies or in db

 

I recommend Sessions

 

place sesssion_start() at the top of all php files

 

on the receiving page of the query place

 

<?

session_start()

if (isset($_POST['searchartist'])) {

$_SESSION['searchartist'] = $_POST['searchartist']

}

 

and back on the main page

 

<?

session_start()

if (isset($_SESSION['searchartist'])) {

$searchartist = $_SESSION['searchartist'];

}

 

 

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.