freemancomputer Posted April 2, 2012 Share Posted April 2, 2012 I just changed around my database and as such I need to update my search form. The way it used to work was a user could use the search bar to look for actors. In changing my database there in no longer a actor column, there are how ever actor_1, actor_2 ... until actor_7. What I am trying to do it set it up so my form looks the same but the back end will look in all the actor columns for the name. So when a user selects actor from the drop down menu it will look in all 7 actor columns. Here is what i had before that worked. for the search bar <form action="/search.php" method="post"> <span class="rulesub">Search: </span><input type="text" name="search"> <select size="1" name="dropdown"> <option value="" selected>Search by...</option> <option value="title">Title</option> <option value="actors">Actors</option> <option value="difficulty">Difficulty 1-5</option> </select> <input type="Submit" value="Search" name="Submit"> </form> for the search page $connect = mysql_connect('localhost', $username, $password) or die ("Unable to connect to host"); mysql_select_db($database) or die ("Unable to connect to database"); $search = empty($_POST['search'])? die ("Please enter search criteria.") : mysql_escape_string($_POST['search']); $dropdown = empty($_POST['dropdown'])? die ("Please select from search criteria.") : mysql_escape_string($_POST['dropdown']); $query = mysql_query("SELECT * FROM movie WHERE $dropdown Like '%$search%'") or die (mysql_error()); if(mysql_num_rows($query) == 0) { printf("Could not find $search while looking in $dropdown, please try again."); //exit; } else{ $num=mysql_numrows($query); mysql_close($connect); ?> Output thanks Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/ Share on other sites More sharing options...
litebearer Posted April 2, 2012 Share Posted April 2, 2012 hint: 1. put your query in a variable 2. echo the above variable Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333426 Share on other sites More sharing options...
dragon_sa Posted April 2, 2012 Share Posted April 2, 2012 why did you break the actors into 7 columns? if the 7 columns represent different categories would it not be easier to just have the 1 actor column, then another column of category or type? Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333428 Share on other sites More sharing options...
freemancomputer Posted April 2, 2012 Author Share Posted April 2, 2012 The point of moving them to 7 diffrent columns is because I will not be the only person adding things to the database. Doing it way makes it easier to have things look the same through out the web site. Not all rows will have a full 7 actors, but they will have at least one. Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333430 Share on other sites More sharing options...
dragon_sa Posted April 2, 2012 Share Posted April 2, 2012 you could still achieve the same by having 1 column that states who added the actor, it would be easier to get a complete list of actors, it would also be easy to get actors only entered by certain users, and it would mean you are not having multiple entries of the same actors anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333431 Share on other sites More sharing options...
freemancomputer Posted April 2, 2012 Author Share Posted April 2, 2012 Maybe im not explaining things correctly. Take a look at my site and go to a movie. The reason why I moved it from one column to 7 is because there are several people that can add movies to the list and by doing it this why I found it makes it easier to make the output the same. drinktothecredits.com Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333434 Share on other sites More sharing options...
dragon_sa Posted April 2, 2012 Share Posted April 2, 2012 have a look at this and see if it suits what your after http://www.stemkoski.com/multiple-column-text-search-of-mysql-database-using-php/ Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333435 Share on other sites More sharing options...
Jessica Posted April 2, 2012 Share Posted April 2, 2012 I would suggest googling "data normalizing". the way you are storing your data is not a great idea, regardless of your reasoning for it. Quote Link to comment https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333648 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.