Jump to content

PHP mysql search


ewok13

Recommended Posts

Hi.

 

Im making a simple search for my website, and I want to know what I can do to remove the results I get from the search?

 

I want it to be removed when updating the page and when going to another page and returning it also has to be removed.

 

Here is the code:

 

<b>Anvend vores søgemaskine og find din uddannelse:</b><br></br>
    <form action="inspiration.php" method="post">
  	<input type="text" name="uddannelse" />
    <input type="submit" name="submit" value="Søg" />
    </form>


<b>
<?php
mysql_connect ("localhost", "root","")  or die (mysql_error());
mysql_select_db ("forum");

$uddannelse = $_POST['uddannelse'];

$sql = mysql_query("select * from uddannelser where uddannelse like '%$uddannelse%'");

while ($row = mysql_fetch_array($sql)){
echo '<br/>'.$row['uddannelse'];
?></b>
    
<b><?php
echo '<br/><br/> Hvad er '.$row['uddannelse'];?></b><br></br><?php echo ''.$row['info'];?>


<b><?php
echo '<br/><br/> Læs mere om '.$row['uddannelse'];?></b><br></br><?php echo '' .$row['fakta'];}


$anymatches=mysql_num_rows($sql); 
if ($anymatches == 0) 
{ 
echo "Der er desværre ingen uddannelse der passer til din søgning<br><br>"; 
} 

?>

Link to comment
Share on other sites

I'm not following what your request it. I understand that a search is being performed. But, I'm a little lost on what is meant by "removing" the results of the search. Are you wanting those records to be deleted or only suppressed when displaying results on the other pages.

 

If you want the records deleted, then you don't need to run a SELECT query at all, just change it to a delete query

$query = "DELETE FROM uddannelser WHERE uddannelse LIKE '%$uddannelse%'";
$result = mysql_query($query);

 

However, if you are wanting to perform that search and then suppress the results of that search on other pages, I see two solutions.

 

1. Don't run the select query at all (unless you do want to display them on that page). Instead, just save the search criteria to a session variable

$_SESSION['uddannelse'] = $uddannelse;

Then on the other pages where you want to suppress those records, just add the same condition with the NOT operator to suppress those records in the results

SELECT * FROM uddannelser WHERE uddannelse NOT LIKE '%{$_SESSION['uddannelse']}%'

 

Or you could run the SELECT query in the above code and retrieve the primary key for those records and save those to a session variable (probably as an array). This would be a little more code, but it would probably be more efficient. Then, again, add an appropriate clause to the other queries to suppress those records

$suppressedIDs = implode(',', $_SESSION['uddannelser_ids']);
$query = "SELECT * FROM uddannelser WHERE id NOT IN ({$suppressedIDs})";

Link to comment
Share on other sites

What I meant was, I search for something in my form, then some result will appear on the same page. I need these results to dissappear again, when I refresh the page of my website. So that I can make a new search without having the old search on the page.

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.