contra10 Posted December 12, 2008 Share Posted December 12, 2008 I have a search box that searches my users and I want to make it specific, ie search for a male in a usa would yield those results, or female in canada would yield those results heres my code so far <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="1" height="500" bgcolor="#5f5f5f" align="center"> <tr><td align="center" bgcolor="black"><b><h3>Search Criteria</b></tr></td> <td align="center" bgcolor="#DEDAD7"><b><h4>RESULTS</b></td> <tr><td align="center" font="red"><h5>ADVERTISMENTS</tr></td> <tr><td><b>Username:</b> <input type="text" name="username" maxlength="50" value="username" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"><p> <b>Gender:</b><p> <input type="radio" name="sexm" value="male" align="left"> Male <br> <input type="radio" name="sexf" value="female" align="right"> Female <p> <b>Age:</b> <input type="text" name="age1" maxlength="02" size="01" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"> To <input type="text" name="age2" maxlength="02" size="01" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"> <p> <b>Country:</b> <select name="country" type="country" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"> <option value="USA" selected>USA</option> <option value="UK">UK</option> <option value="Albania">Albania</option> <option value="Algeria">Algeria</option> <option value="American Samoa">American Samoa</option> <option value="Andorra">Andorra</option> <option value="Angola">Angola</option> <option value="Anguilla">Anguilla</option> <option value="Antigua">Antigua</option> <option value="Argentina">Argentina</option> <option value="Armenia">Armenia</option> <option value="Aruba">Aruba</option> <option value="Australia">Australia</option> <option value="Austria">Austria</option> <option value="Azerbaijan">Azerbaijan</option> <option value="Bahamas">Bahamas</option> <option value="Bahrain">Bahrain</option> <option value="Bangladesh">Bangladesh</option> <option value="Barbados">Barbados</option> <option value="Barbuda">Barbuda</option> <option value="Belgium">Belgium</option> <option value="Belize">Belize</option> <option value="Benin">Benin</option> <option value="Bermuda">Bermuda</option> <option value="Bhutan">Bhutan</option> <option value="Bolivia">Bolivia</option> <option value="Bonaire">Bonaire</option> <option value="Botswana">Botswana</option> <option value="Brazil">Brazil</option> <option value="Virgin islands">British Virgin isl.</option> <option value="Brunei">Brunei</option> <option value="Bulgaria">Bulgaria</option> <option value="Burundi">Burundi</option> <option value="Cambodia">Cambodia</option> <option value="Cameroon">Cameroon</option> <option value="Canada">Canada</option> <option value="Cape Verde">Cape Verde</option> <option value="Cayman isl">Cayman Islands</option> <option value="Central African Rep">Central African Rep.</option> <option value="Chad">Chad</option> <option value="Channel isl">Channel Islands</option> <option value="Chile">Chile</option> <option value="China">China</option> <option value="Colombia">Colombia</option> <option value="Congo">Congo</option> <option value="cook isl">Cook Islands</option> <option value="Costa Rica">Costa Rica</option> <option value="Croatia">Croatia</option> <option value="Curacao">Curacao</option> <option value="Cyprus">Cyprus</option> <option value=" Czech Republic">Czech Republic</option> <option value= "Denmark">Denmark</option> <option value="Djibouti">Djibouti</option> <option value="Dominica">Dominica</option> <option value="Dominican Republic">Dominican Republic</option> <option value="Ecuador">Ecuador</option> <option value="Egypt">Egypt</option> <option value="El Salvador">El Salvador</option> <option value="Equatorial Guinea">Equatorial Guinea</option> <option value="Eritrea">Eritrea</option> <option value="Estonia">Estonia</option> <option value="Ethiopia">Ethiopia</option> <option value="Faeroe isl">Faeroe Islands</option> <option value="Fiji">Fiji</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="French Guiana">French Guiana</option> <option value="French Polynesia">French Polynesia</option> <option value="Gabon">Gabon</option> <option value="Gambia">Gambia</option> <option value="Georgia">Georgia</option> <option value="Gemany">Germany</option> <option value="Ghana">Ghana</option> <option value="Gibraltar">Gibraltar</option> <option value="GB">Great Britain</option> <option value="Greece">Greece</option> <option value="Greenland">Greenland</option> <option value="Grenada">Grenada</option> <option value="Guadeloupe">Guadeloupe</option> <option value="Guam">Guam</option> <option value="Guatemala">Guatemala</option> <option value="Guinea">Guinea</option> <option value="Guinea Bissau">Guinea Bissau</option> <option value="Guyana">Guyana</option> <option value="Haiti">Haiti</option> <option value="Honduras">Honduras</option> <option value="Hong Kong">Hong Kong</option> <option value="Hungary">Hungary</option> <option value="Iceland">Iceland</option> <option value="India">India</option> <option value="Indonesia">Indonesia</option> <option value="Irak">Irak</option> <option value="Iran">Iran</option> <option value="Ireland">Ireland</option> <option value="Northern Ireland">Ireland, Northern</option> <option value="Israel">Israel</option> <option value="Italy">Italy</option> <option value="Ivory Coast">Ivory Coast</option> <option value="Jamaica">Jamaica</option> <option value="Japan">Japan</option> <option value="Jordan">Jordan</option> <option value="Kazakhstan">Kazakhstan</option> <option value="Kenya">Kenya</option> <option value="Kuwait">Kuwait</option> <option value="Kyrgyzstan">Kyrgyzstan</option> <option value="Latvia">Latvia</option> <option value="Lebanon">Lebanon</option> <option value="Liberia">Liberia</option> <option value="Liechtenstein">Liechtenstein</option> <option value="Lithuania">Lithuania</option> <option value="Luxembourg">Luxembourg</option> <option value="Macau">Macau</option> <option value="Macedonia">Macedonia</option> <option value="Madagascar">Madagascar</option> <option value="Malawi">Malawi</option> <option value="Malaysia">Malaysia</option> <option value="Maldives">Maldives</option> <option value="Mali">Mali</option> <option value="Malta">Malta</option> <option value="Marshall isl">Marshall Islands</option> <option value="Martinique">Martinique</option> <option value="Mauritania">Mauritania</option> <option value="Mauritius">Mauritius</option> <option value="Mexico">Mexico</option> <option value="Micronesia">Micronesia</option> <option value="Moldova">Moldova</option> <option value="Monaco">Monaco</option> <option value="Mongolia">Mongolia</option> <option value="Montserrat">Montserrat</option> <option value="Morocco">Morocco</option> <option value="Mozambique">Mozambique</option> <option value="Myanmar">Myanmar/Burma</option> <option value="Namibia">Namibia</option> <option value="Nepal">Nepal</option> <option value="Netherlands">Netherlands</option> <option value="Netherlands Antilles">Netherlands Antilles</option> <option value="New Caledonia">New Caledonia</option> <option value="New Zealand">New Zealand</option> <option value="Nicaragua">Nicaragua</option> <option value="Niger">Niger</option> <option value="Nigeria">Nigeria</option> <option value="Norway">Norway</option> <option value="Oman">Oman</option> <option value=""Palau>Palau</option> <option value="Panama">Panama</option> <option value="Papua New Guinea">Papua New Guinea</option> <option value="Paraguay">Paraguay</option> <option value="Peru">Peru</option> <option value="Philippines">Philippines</option> <option value="Poland">Poland</option> <option value="Portugal">Portugal</option> <option value="Puerto Rico">Puerto Rico</option> <option value="Qatar">Qatar</option> <option value="Reunion">Reunion</option> <option value="Rwanda">Rwanda</option> <option value="Saba">Saba</option> <option value="Saipan">Saipan</option> <option value="Saudi Arabia">Saudi Arabia</option> <option value="Scotland">Scotland</option> <option value="Senegal">Senegal</option> <option value="Seychelles">Seychelles</option> <option value="Sierra Leone">Sierra Leone</option> <option value="Singapore">Singapore</option> <option value="Slovac Republic">Slovak Republic</option> <option value="Slovenia">Slovenia</option> <option value="South Africa">South Africa</option> <option value="South Korea">South Korea</option> <option value="Spain">Spain</option> <option value="Sri Lanka">Sri Lanka</option> <option value="Sudan">Sudan</option> <option value="Suriname">Suriname</option> <option value="Swaziland">Swaziland</option> <option value="Sweden">Sweden</option> <option value="Switzerland">Switzerland</option> <option value="Syria">Syria</option> <option value="Taiwan">Taiwan</option> <option value="Tanzania">Tanzania</option> <option value="Thailand">Thailand</option> <option value="Togo">Togo</option> <option value="Trinidad-Tobago">Trinidad-Tobago</option> <option value="Tunesia">Tunisia</option> <option value="Turkey">Turkey</option> <option value="Turkmenistan">Turkmenistan</option> <option value="United Arab Emirates">United Arab Emirates</option> <option value="U.S. Virgin isl">U.S. Virgin Islands</option> <option value="USA">U.S.A.</option> <option value="Uganda">Uganda</option> <option value="United Kingdom">United Kingdom</option> <option value="Urugay">Uruguay</option> <option value="Uzbekistan">Uzbekistan</option> <option value="Vanuatu">Vanuatu</option> <option value="Vatican City">Vatican City</option> <option value="Venezuela">Venezuela</option> <option value="Vietnam">Vietnam</option> <option value="Wales">Wales</option> <option value="Yemen">Yemen</option> <option value="Zaire">Zaire</option> <option value="Zambia">Zambia</option> <option value="Zimbabwe">Zimbabwe</option> </select><p> <input type="submit" name="submit" value="submit"> <td width="600" bgcolor="#DEDAD7"><?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { $query = "SELECT * FROM users"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $sexs = "{$_POST['sexm']}"; $user = "{$row['id']}"; $userq = "{$row['username']}"; $sex = "{$row['sex']}"; echo "<TABLE width=550 bgcolor=black border=1 align=center cellpadding=4 cellspacing=0>"; echo "<tr>"; echo "<td width='35%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'>$userq<p>"; echo "$sex</td>"; echo "</tr>"; } if ($sexs == $sex){ echo ($userq); } } ?></td> </table> </form> <? } ?> Quote Link to comment Share on other sites More sharing options...
waterssaz Posted December 12, 2008 Share Posted December 12, 2008 Hi, just a quick bit if advice. I would do the seraching in the query and not in the results that are returned from the query. :-) Quote Link to comment Share on other sites More sharing options...
Brian W Posted December 12, 2008 Share Posted December 12, 2008 something like $query = "SELECT * FROM users WHERE sex = $Sex AND Country = ".$_POST['country']; Quote Link to comment Share on other sites More sharing options...
contra10 Posted December 13, 2008 Author Share Posted December 13, 2008 should i put the $query = "SELECT * FROM users WHERE sex = $Sex AND Country = ".$_POST['country']; and the beginning and write an elseif statement how exactly do i put it together...would that also mean i would have to put multiple queryies Quote Link to comment Share on other sites More sharing options...
contra10 Posted December 13, 2008 Author Share Posted December 13, 2008 ok i figuerd it out before but the problem was that it only showed one result // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("registration") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { $query = "SELECT * FROM users"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $user = "{$row['id']}"; $userq = "{$row['username']}"; $mycountry = "{$row['country']}"; $sex = "{$row['sex']}"; $postuser = $_POST['username']; $country = $_POST['country']; $postsex = $_POST['sex']; } if ($postsex == $sex){ echo "<TABLE width=650 border=1 align=center cellpadding=4 cellspacing=0>"; echo "<tr>"; echo "<td width='35%'><a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2'>$userq<p>"; echo "$mycountry $sex</a></FONT></td>"; echo "</tr>"; } } ?> thats an example but if i check male all it shows is one male in results not all the males in the database 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.