Jarel101 Posted July 15, 2011 Report Share Posted July 15, 2011 Hi, I'm creating a image gallery and I'm about 90% complete. One of my final objectives is to create a keyword search for my image gallery. I have 4 fields in my DB, (id,image,description,keywords) I want to be able to enter keywords into a search and the images with there descriptions show up. I've been searching the internet and Youtube and I can't find any tutorials that I fully comprehend. I already have the keywords in my mysql. After inserting the form, text field and search button I don't really know the next step. For this project I'm using Dreamweaver Cs5, I'm not really an experienced coder I rely heavily on dreamweaver for my code, I just make minor tweaks. So if anyone has an answer to my problem please break down and simplify your answer I'm still a beginner. Thanks in advance. ps If anyone knows of any other video tutorials of this process please inform me, it would be greatly appreciated, thank you. Quote Link to comment Share on other sites More sharing options...
Archadian28 Posted July 15, 2011 Report Share Posted July 15, 2011 (edited) I believe you are looking for the LIKE method in mysql. http://www.mysqltutorial.org/sql-like-mysql.aspx Ok say you have a first and last name in the database. id first_name last_name 1 John Smith 2 Joe Blow 3 Samantha Beth Now in order to search you can use this: "SELECT first_name, last_name FROM users LIKE 'J%'" and that will return 2 rows. Since there are 2 names that start with J and this could be first or last name. The % tells mysql which way to search, after the letter J% is searching right, before the letter %J searches left and %J% will search both. "SELECT first_name, last_name FROM users LIKE '%th'" will return the names that end in 'th'. Your form would look like this: <form method="post" action="somepage.php"> <input type="text" name="search" size="20" /> <input type="submit" name="submit" value="Search" /> </form> PHP: name="search" would be $_POST['search'] <-- holds the value that was inputted into the text field. name="submit" would be $_POST['submit'] <-- you can do a check to see if the button was clicked. if(isset($_POST['submit']) && isset($_POST['search'])) { // search the database here } else { // either $_POST['search'] or $_POST['submit'] was not set. } Hopefully this clears it up for you . Edited July 15, 2011 by Archadian Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.