Jump to content

Recommended Posts

Hi,

 

Im trying to create a form that will allow a user to search for another user via their city and what sports they like. I have so far three sections of code:

 

<?php

if(isset($_POST['submit'])) {

    // The form has been sent so show the results
} else {

    // Show the form
}

?>
 

That piece of code i have no idea on but it basically needs to check if the form has been subbmited, then show the search results if it has and if not then display the search form.

 

 

<form name="input2" action="search.php" method="post" >

<b>City:</b> <name="licity">
 
<?php

echo'<select name="cities">';

foreach($citynames as $city){
echo'<option value="'.$city.'">'.$city.'</option>';
}
echo'</select>';
?>


<b>Sports:</b> <name="lisports">
 
<?php

echo'<select name="sports">';

foreach($sportnames as $sports){
echo'<option value="'.$sports.'">'.$sports.'</option>';
}
echo'</select>';
?>
 

<input type="submit" value="Search" name="lisearch">
</form>

 

This part is just the form to list the different cities and sports so the user can search via both of them.

 

 

<?php

$query = "SELECT user.user_id, user.user_firstname, user.user_surname ".
     
    
"FROM user, usersport ".
    
    
"WHERE user.user_id = usersport.usersport_user_id
 
AND usersport_sport_id = '".$_POST['sport']."'
AND user_city = '".$_POST['city']."'
AND user_id != '".$_SESSION['id']."'";
?>

 

This third part gets the data from the database tables depending on what the user has searched for.

 

 

Anyone have any ideas? I know its alot of code and might be confusing but any help would be great! Thanks! :)

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

What you have there is more like a select this and that....it shows results.

 

Do you want information on how to do a normal search? using LIKE ?

 

Personally i like using fulltext search as it simplifies multiple keyword searches.

https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html

Link to comment
https://forums.phpfreaks.com/topic/287700-php-search/#findComment-1475840
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.