Jump to content

sql query problems


franknu

Recommended Posts

ok, i want that when the user select type and make and there is a Categories for  type and make to display what is on the database

the problem is that i am getting  No Results found any idea why

here is my code

[code=php:0]

$query =
  "SELECT * ".
  "FROM `business_info` ".
  "WHERE `make`=='make' ".
    "AND `type`=='type'".
    ((!empty($Categories)) ? " AND `Categories` LIKE '%".$Categories."%'":'');


$result = mysql_query($query) or die (mysql_error());
$num_result = mysql_num_rows($result);
  echo "<table>";
if($num_result <= 0){
    echo("No Results found.");
    exit;
[/code]
Link to comment
Share on other sites

i did it with only one and i was still getting  No results found

i have a make, type and categories on the row

this one works
[code=php:0]

$query = "SELECT * FROM `business_info` WHERE  Categories LIKE '%".$Categories."%'";

[/code] but it only search for categories it doen't mind what is on type and make

please help
Link to comment
Share on other sites

thi is are new changes

[code=php:0]

$query =
  "SELECT *
  FROM `business_info`
  WHERE `make`='make'
    AND `type`='type'"
      AND Categories LIKE '%".$Categories."%'";
[/code]

but this is the error message that i got

Parse error: syntax error, unexpected T_STRING in /home/townsfin/public_html/business_display.php on line 45
Link to comment
Share on other sites

You will always have to use the backslashes when using wildcards and or variables


$query =
  "SELECT *
  FROM `business_info`
  WHERE `make`='make'
    AND `type`='type'"
      AND Categories LIKE \"%$Categories%\" ";

Try removing the fullstops

Link to comment
Share on other sites

also shouldnt make and type be put into variables???

$query =
 "SELECT *
 FROM business_info
 WHERE make=\"$make\"
   AND type=\"$type\"
     AND Categories LIKE \"%$Categories%\" ";
cos otherwise you are searching for something that has make stored in the make field??

unless you want

$query =
  "SELECT make, type
  FROM business_info
  WHERE Categories LIKE \"%$Categories%\" ";
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.