Ruud Hermans Posted July 3, 2009 Share Posted July 3, 2009 I am trying to edit the following script; <? //connect to mysql and the right database include 'config.php'; $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM news WHERE message LIKE '%$search%'"); //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["title"]; $message=$r["message"]; $who=$r["who"]; $date=$r["date"]; $time=$r["time"]; $id=$r["id"]; //display the row echo "$title <br> $message <br> $who <br> $date | $time <br>"; } ?> I allready changed the part to connect to MySQL and the databse "test" but I do not understand this part; //change whatevertable to the mysql table you're using Does this refferes to the follwing line of code? $result = mysql_query("SELECT * FROM news WHERE message LIKE '%$search%'"); If the table was called members and I want to change it so it searches trough the phonenumbers do I need to change it in this way then? $result = mysql_query("SELECT * FROM members WHERE phonenumber LIKE '%$search%'"); And what does this part do exactly? $title=$r["title"]; $message=$r["message"]; $who=$r["who"]; $date=$r["date"]; $time=$r["time"]; $id=$r["id"]; Note: I hope I posted in the right forum this time, I thought it reffered to MySQL so I presume it should be posted here. Quote Link to comment Share on other sites More sharing options...
Hybride Posted July 3, 2009 Share Posted July 3, 2009 A rough translation of your $result query is this: SELECT columns FROM table WHERE whatcolumnyouwant LIKE '%$whatyouaresearchingfor%' So, "whatevertable" would be the table (news), and "whatevercolumn" would whatcolumnyouwant (message). Your syntax for searching the phone number is correct, assuming you have a table named "members" and a column "phonenumber". This here: $title=$r["title"]; $message=$r["message"]; $who=$r["who"]; $date=$r["date"]; $time=$r["time"]; $id=$r["id"]; Is the result of your mysql_fetch_array query, sent to the variable $r. These are the names of columns in your table (so in this case, you have a table named title, message, who, date, time, id.) In the next line, you asked for them to be printed/shown. Quote Link to comment Share on other sites More sharing options...
Ruud Hermans Posted July 3, 2009 Author Share Posted July 3, 2009 Edited it like this; <? //connect to mysql and the right database include 'config.php'; $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM members WHERE name LIKE '%$search%'"); //grab all the content while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $name=$r["name"]; $email=$r["email"]; $location=$r["location"]; //display the row echo "$name <br> $email <br> $location <br>"; } ?> The problem is that it spits the following out when I run it knowing the edited ino is correct. $email $location "; } ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted July 4, 2009 Share Posted July 4, 2009 What are you trying to do??? Quote Link to comment Share on other sites More sharing options...
Ruud Hermans Posted July 4, 2009 Author Share Posted July 4, 2009 What are you trying to do??? I am trying to make a search form to search trough a MySQL database. THe other part of it is; Search: <form method="post" action="search.php"> <input type="text" name="search" size=25 maxlength=25> <input type="Submit" name="Submit" value="Submit"> </form> Quote Link to comment Share on other sites More sharing options...
fenway Posted July 4, 2009 Share Posted July 4, 2009 Well, if you need to search multiple columns, your options are (a) multiple LIKE conditions, (b) FULLTEXT indexing, or © Sphinx/Lucene. 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.