scott botkins Posted July 11, 2007 Share Posted July 11, 2007 Hey Guys, Here's my problem which I think may be simple to solve hopefully, I'm new to searching mysql databases. I have this setup http://www.invisionblue.com/designs/gdogs which goes along with http://www.invisionblue.com/designs/gdogs/db.gif It has over 100,000 listings. Right now i have it displaying the results by the SZNummer column. However I'm wanting it to be where I type in the dog name (Hundename) it will display the results instead of by SZNummer. You'll notice the tables and information isn't in english, that's because the client is from another country. Below is my code, should be simple I believe. Thanks in advance for the help! <form action="index.php" method="post"> <p>ID For Hundename: <input type="text" name="id" /></p> <p><input type="submit" /></p> </form> <? //connect to mysql //change user and password to your mySQL name and password mysql_connect("host","user","pass"); //(host, username, password) //select which database you want to edit mysql_select_db("garydogs"); //select the table $id = (int)$_POST['id']; $result = mysql_query("select * from Hundestamm WHERE ( `Hundestamm` . `SZNummer` = $id ) limit 1"); //grab all the content while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $title=$r["Hundename"]; $zwing=$r["Zwingername"]; $ges=$r["Geschlecht"]; //display the row echo "<b>Hundename:</b><br>$title<br><br><b>Zwingername:</b><br>$zwing<br><br><b>Geschlecht:</b><br>$ges<br><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59456-solved-simple-mysql-search-problem/ Share on other sites More sharing options...
Wildbug Posted July 11, 2007 Share Posted July 11, 2007 Change the column to Hundename, escape it, make sure it's in quotes... <?php // ... $result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename = "%s"', mysql_real_escape_string($_POST['id'])); // ... or a "starts with" variant $result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename LIKE "%s%%"', mysql_real_escape_string($_POST['id'])); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59456-solved-simple-mysql-search-problem/#findComment-295524 Share on other sites More sharing options...
scott botkins Posted July 11, 2007 Author Share Posted July 11, 2007 I get the following error when I use your code... Parse error: parse error, unexpected ';' in /designs/gdogs/index.php on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/59456-solved-simple-mysql-search-problem/#findComment-295561 Share on other sites More sharing options...
Wildbug Posted July 11, 2007 Share Posted July 11, 2007 Right, a missing closing parenthesis in both cases. Corrected: <?php // ... $result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename = "%s"', mysql_real_escape_string($_POST['id']))); // ... or a "starts with" variant $result = mysql_query(sprintf('SELECT * FROM Hundestamm WHERE Hudename LIKE "%s%%"', mysql_real_escape_string($_POST['id']))); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59456-solved-simple-mysql-search-problem/#findComment-295580 Share on other sites More sharing options...
scott botkins Posted July 11, 2007 Author Share Posted July 11, 2007 Awesome, thanks works perfect. Quote Link to comment https://forums.phpfreaks.com/topic/59456-solved-simple-mysql-search-problem/#findComment-295588 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.