Jump to content

[SOLVED] searching mysql with php :(


kendallkamikaze

Recommended Posts

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="&#167;">&#167;
        </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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.