ewok13 Posted April 26, 2012 Share Posted April 26, 2012 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/261648-php-mysql-search/ Share on other sites More sharing options...
Psycho Posted April 26, 2012 Share Posted April 26, 2012 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})"; Quote Link to comment https://forums.phpfreaks.com/topic/261648-php-mysql-search/#findComment-1340749 Share on other sites More sharing options...
ewok13 Posted April 26, 2012 Author Share Posted April 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261648-php-mysql-search/#findComment-1340769 Share on other sites More sharing options...
Jessica Posted April 26, 2012 Share Posted April 26, 2012 Just put the search form at the top so you don't have to refresh. When a user hits refresh the browser will resubmit (or ask to) the previously submitted values. You can't control that. Quote Link to comment https://forums.phpfreaks.com/topic/261648-php-mysql-search/#findComment-1340770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.