Does anyone know how to make a search with the get method? Or know a place I can learn it from? I want to do one for my blog.
Something to this nature. Add db connection commands.. and change to your structure. and thats the basics of it <?php // ADD YOUR DATABASE CONNECTION STUFF HERE. $term = $_GET['term']; $query = "SELECT * FROM `TABLE` WHERE `Value` = '".mysql_real_escape_string($term)."'"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['name']; echo $row['column name']; echo $row['other stuff']; } ?> PHP:
If you want more leeway in what you're searching for, using % around the variable. ->SELECT * FROM table WHERE column LIKE %$term% OR othercolumn LIKE %$term% And escape it from bad characters, of course.
I've made my search and it works fine, but I want to hide the blogs that are showing, so that they only show when you search for them. www.venardveloria.com/Search.php Please help.
You only want to echo your blog posts after you've search. <form method="post" action="<?php $_SERVER[PHP_SELF]; ?>"> <input type="text" name="search" size=25 maxlength=25> <input type="Submit" name="Submit" value="Search"> </form> <?php if (isset($_POST['Submit'])) { $result = mysql_query("SELECT * FROM table WHERE column LIKE %search%"); while ($row = mysql_fetch_array($result)) { echo all your data from your blog posts } } ?> PHP:
What about errors, like if the search term wasn't found? Where and how do I place the die statement? And how can I order the items that were found by date? Sorry for the troubles, I don't know much PHP.
This part I'm not sure of. But I think it will work. <form method="post" action="<?php $_SERVER[PHP_SELF]; ?>"> <input type="text" name="search" size=25 maxlength=25> <input type="Submit" name="Submit" value="Search"> </form> <?php if (isset($_POST['Submit'])) { $result = mysql_query("SELECT * FROM table WHERE column LIKE %search% ORDER BY date"); if (!$result) { echo "Sorry. No posts were found that matched your search query."; } else { while ($row = mysql_fetch_array($result)) { echo all your data from your blog posts } } } ?> PHP: