Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/260159-search-form/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333430
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333431
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/260159-search-form/#findComment-1333434
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.