Jump to content

ferellie

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ferellie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am using the following code to search for information in my database using keywords which are inputted into a search box. foreach($_POST as $key => $val) { // This loops through the form variables $$key = $val; // Assigns variables with the same names as the input names } // i.e. the text box inputSearch would have a variable name of $inputSearch // read data from database $result = mysql_query("select * from $table WHERE keywords LIKE '%$inputSearch%' order by id desc limit $rows", $link) or die ("Could not read data because ".mysql_error()); Problem is, the query results are not quite what I had in mind! If the field contained the words 'one two three' and the user searched for 'three two' the query would return nothing. Is there a way of modifying the search to accomplish this? I want my search to find any matching words. Thanks again, Peter
  2. [!--quoteo(post=351329:date=Mar 3 2006, 02:06 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 3 2006, 02:06 PM) [snapback]351329[/snapback][/div][div class=\'quotemain\'][!--quotec--] since web is a string you have to encase it in quotes [code]$result = mysql_query("select * from $table WHERE categories LIKE '%web%' order by id desc limit $rows", $link) or die ("Could not read data because ".mysql_error());[/code] Ray [/quote] [!--quoteo(post=351329:date=Mar 3 2006, 02:06 PM:name=craygo)--][div class=\'quotetop\']QUOTE(craygo @ Mar 3 2006, 02:06 PM) [snapback]351329[/snapback][/div][div class=\'quotemain\'][!--quotec--] since web is a string you have to encase it in quotes [code]$result = mysql_query("select * from $table WHERE categories LIKE '%web%' order by id desc limit $rows", $link) or die ("Could not read data because ".mysql_error());[/code] Ray [/quote] thank you but how do I get the text from the input box to replace the text 'web' in my code? Thanks
  3. I am using table with several fields which I display in a div no problem. I need to display all fields on a seperate page where the categories field contains the string web as an example. This is my code.. <?php include "config.php"; // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // read data from database $result = mysql_query("select * from $table WHERE categories LIKE %web% order by id desc limit $rows", $link) or die ("Could not read data because ".mysql_error()); ?> AND TO DISPLAY IN A DIV <?php // print the data in a div if (mysql_num_rows($result)) { while ($qry = mysql_fetch_array($result)) { ?> <div id="business"> <?php print "$qry[business]<br>"; ?> </div> <div id="businessdescription"> Business description:</div> <?php print "$qry[description]<br>"; ?> <div id="contactname"> Contact person:</div> <?php print "$qry[name]<br>"; ?> <div id="location"> Location:</div> <?php print "$qry[town]"; ?> &nbsp; <?php print "$qry[postcode]<br>"; ?> <div id="telephone"> Telephone:</div> <?php print "$qry[phone]<br>"; ?> <div id="website"> <a href=" <?php print "$qry[website]"; ?> ">Visit Company Website</a></div> <div id="endseperator"></div> <?php } } mysql_close(); ?> MY CONFIG.PHP CONTENTS IS <?php $server = "localhost"; // server to connect to. $database = "pages"; // the name of the database. $db_user = "pages"; // mysql username to access the database with. $db_pass = "pass"; // mysql password to access the database with. $table = "denb"; // database table $rows = 500; // the number of table rows to display ?> I would really appreciate any help, Thank you.
×
×
  • 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.