kendallkamikaze Posted February 5, 2009 Share Posted February 5, 2009 alright so i own a horse simulation game. Players are able to brand horses. I'm trying to create a search area for them to be able to search the brands of horses. This is the code I have: <?php include 'header.php'; ?> <font face="verdana" size="1"> Results of Your Search: <br> <TABLE BORDER='1' WIDTH='850' CELLSPACING='2' CELLPADDING='1'> <font-face='verdana' size='1'> <tbody> <td width='100' ALIGN='CENTER'><font class='tableheader'> Horse ID</font></td> <td width='250' ALIGN='CENTER'><font class='tableheader'> Horses Name</font></td> <td width='250' ALIGN='CENTER'><font class='tableheader'> Breed</font></td> <td width='150' ALIGN='CENTER'><font class='tableheader'> Points</font></td> <td width='150' ALIGN='CENTER'><font class='tableheader'> Brand</font></td> <td width='100' ALIGN='CENTER'><font class='tableheader'> Owner</font></td> </table> <?php $brand=$_POST['brand']; $result = mysql_query("select * from horsedata where brand like '%$brand%%' "); while($r=mysql_fetch_array($result)) { $id=$r["id"]; $Name=$r["Name"]; $Owner=$r["Owner"]; $Breed=$r["Breed"]; $Exp=$r["Exp"]; $Gender=$r["Gender"]; $Points=$r["Points"]; $Height=$r["Height"]; $Registrations=$r["Registrations"]; $Records=$r["Records"]; $Speed=$r["Owner"]; $Scope=$r["Scope"]; $Endurance=$r["Endurance"]; $Power=$r["Power"]; $Obedience=$r["Obedience"]; $Sociability=$r["Sociability"]; $Intelligence=$r["Intelligence"]; $Sire=$r["Sire"]; $Dam=$r["Dam"]; $Foals=$r["Foals"]; $Awards=$r["Awards"]; $Image=$r["Image"]; $brand=$r["brand"]; //display the row echo " <TABLE BORDER='1' WIDTH='850' CELLSPACING='2' CELLPADDING='1'> <font-face='verdana' size='1'> <tbody> <td class='tablecont' width='100' ALIGN='CENTER'><font size='2pt'> <a href='horse_individual.php?id=$id'>$id</a></font></td> <td class='tablecont' width='250' ALIGN='CENTER'><font size='2pt'> $Name</td> <td class='tablecont' width='250' ALIGN='CENTER'><font size='2pt'> $Breed</font></td> <td class='tablecont' width='150' ALIGN='CENTER'><font size='2pt'> $Points</font></td> <td class='tablecont' width='150' ALIGN='CENTER'><font size='2pt'> $brand</font></td> <td class='tablecont' width='100' ALIGN='CENTER'><font size='2pt'> <a href='player_individual.php?id=$Owner'>$Owner</a></font></td> </table> "; } ?> <?php include 'footer.php'; ?> Perviously I was trying to search using this method: <font size='2pt'><form name="bybrand" method="post" action="horse_searchbrand.php"><font face="verdana" size="1"> Search Brand Below [NOT FUNCTIONAL YET!]: <br> <select name="brand"> <option value="none">Select a letter/character. <option value="A">A <option value="B">B <option value="C">C <option value="D">D <option value="E">E <option value="F">F <option value="G">G <option value="H">H <option value="I">I <option value="J">J <option value="K">K <option value="L">L <option value="M">M <option value="N">N <option value="O">O <option value="P">P <option value="Q">Q <option value="R">R <option value="S">S <option value="T">T <option value="U">U <option value="V">V <option value="W">W <option value="X">X <option value="Y">Y <option value="Z">Z <option value="0">0 <option value="1">1 <option value="2">2 <option value="3">3 <option value="4">4 <option value="5">5 <option value="6">6 <option value="7">7 <option value="8">8 <option value="9">9 <option value="§">§ </select> <input type="submit" value="search"></font></form> I've now switched to another method because I'm not sure which would work better: <form name="bybrand" method="post" action="horse_searchbrand.php"><font face="verdana" size="1">Brand:<input name="Brand" id="Brand" type="text"> <input value="search" type="submit"></font></form> any ideas? Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/ Share on other sites More sharing options...
gevans Posted February 5, 2009 Share Posted February 5, 2009 Will the people that are using this know what the brands are (I'd expect so)? If yes I'd go with the second option as they can just type in the brand name that they want to find. Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755374 Share on other sites More sharing options...
Maq Posted February 5, 2009 Share Posted February 5, 2009 I've now switched to another method because I'm not sure which would work better: Why don't you test it out? They are both totally different. Or you could have both... If the user doesn't know the exact breed then they can go by letter. If they do, then they can type in the exact name. Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755379 Share on other sites More sharing options...
kendallkamikaze Posted February 5, 2009 Author Share Posted February 5, 2009 I've now switched to another method because I'm not sure which would work better: Why don't you test it out? They are both totally different. Or you could have both... If the user doesn't know the exact breed then they can go by letter. If they do, then they can type in the exact name. the one i switched it to is more efficent. thats why i have it on there now...but the search itself is not working properly. you type in something to search, and it brings back every single horse with a brand, not just what you searched for Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755381 Share on other sites More sharing options...
gevans Posted February 5, 2009 Share Posted February 5, 2009 $result = mysql_query("select DISTINCT brand from horsedata where brand like '%$brand%%' "); Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755387 Share on other sites More sharing options...
kendallkamikaze Posted February 5, 2009 Author Share Posted February 5, 2009 $result = mysql_query("select DISTINCT brand from horsedata where brand like '%$brand%%' "); didnt work, it brought back only the brands, not the rest of the horsedata, and they were not the brand i searched for either. I searched 'jenn' and was getting things back like: 'Technicolor Fri' Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755394 Share on other sites More sharing options...
dennismonsewicz Posted February 5, 2009 Share Posted February 5, 2009 try taking out the double %% and make it a single % $result = mysql_query("select DISTINCT brand from horsedata where brand like '%$brand%' "); Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755395 Share on other sites More sharing options...
kendallkamikaze Posted February 5, 2009 Author Share Posted February 5, 2009 try taking out the double %% and make it a single % $result = mysql_query("select DISTINCT brand from horsedata where brand like '%$brand%' "); nope, still brings back everything and for some reason when i add the distinct, it doesnt bring back any of the other info i need for the table, it brings back just the brand, not the name; breed; etc. Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755399 Share on other sites More sharing options...
dennismonsewicz Posted February 5, 2009 Share Posted February 5, 2009 try taking out the double %% and make it a single % $result = mysql_query("select DISTINCT brand from horsedata where brand like '%$brand%' "); nope, still brings back everything and for some reason when i add the distinct, it doesnt bring back any of the other info i need for the table, it brings back just the brand, not the name; breed; etc. try this $result = mysql_query("select DISTINCT * from horsedata where brand like '%$brand%' "); Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755400 Share on other sites More sharing options...
kendallkamikaze Posted February 5, 2009 Author Share Posted February 5, 2009 still brought back all horses with brands instead of just the one i searched for ;( damn php Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755403 Share on other sites More sharing options...
Maq Posted February 5, 2009 Share Posted February 5, 2009 yeah should be (uppercase B): $brand=$_POST['Brand']; Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755407 Share on other sites More sharing options...
gevans Posted February 5, 2009 Share Posted February 5, 2009 List everything you want from the database, I only selected brand... $result = mysql_query("select DISTINCT brand from horsedata where brand like '%$brand%' "); List the other fields; $result = mysql_query("select DISTINCT brand, another_field from horsedata where brand like '%$brand%' "); Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755411 Share on other sites More sharing options...
kendallkamikaze Posted February 5, 2009 Author Share Posted February 5, 2009 yeah should be (uppercase B): $brand=$_POST['Brand']; that fixed it its now functioning ! <3 Link to comment https://forums.phpfreaks.com/topic/143954-solved-searching-mysql-with-php/#findComment-755416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.