Jump to content

can i Double query in the sale loop


franknu

Recommended Posts

Can i do double query

 

for example i want this code to search

if(!$Categories ||!$make){

  echo "You have not enter all fields";
  exit;
  }
$db = mysql_connect($host, $username, $password) or die(mysql_error()); 
mysql_select_db($database) or die(mysql_error()); 


$bizwebpage2 = (isset($_FILES['bizwebpage2']) ? $_FILES['bizwebpage2']:'');
$Picture1 =  (isset($_FILES['Picture1']) ? $_FILES['Picture1']:'');


if(isset($_GET['Categories'])){
    $Categories = addslashes($_GET['Categories']);
    }
    else
{
    echo(""); 
}

$query = 
  "SELECT * 
  FROM business_info 
  WHERE make=\"$make\" 
    AND type=\"$type\"
      AND Categories LIKE \"%$Categories%\" ";
  OR
here is the line what i want to add 
$query = "SELECT * FROM business info WHERE make =\"$make\"
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 With this word.  Please try similars words or<br>
    Look for surrounding <b>Towns </b>or  just <b> State.</b> <br>
<a href="index.php"> GO BACK </a>
.");
    exit;
}

This is the error that i get

Parse error: syntax error, unexpected T_LOGICAL_OR in /home/townsfin/public_html/business_display.php on line 47

 

Link to comment
https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/
Share on other sites

i made some changes to make work more efficience here is the eror

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') || (make ="Massachusetts" AND Categories like "%nightclub%") "' at line 1

 

 

here is my code

$query="SELECT * FROM business_info WHERE ((make=\"$make\" AND type=\"$type\")AND Categories like \"%$Categories%\"))
|| (make =\"$make\"
AND Categories like \"%$Categories%\") \" ";

In MySQL you use single quotes to enclose variables. IE:

 

<?php
$query="SELECT * FROM business_info WHERE ((make='$make' AND type='$type')AND Categories like '%$Categories%'))
|| (make ='$make'
AND Categories like '%$Categories%')";

 

Proper syntax helps sometimes.

<?php
$query="SELECT * FROM business_info WHERE ((make='$make' AND type='$type') AND Categories like '%$Categories%'))
|| (make ='$make'
AND Categories like '%$Categories%')";

 

Probably should have a space between the ) and the AND. See if that works.

<?php

$query="SELECT * FROM business_info WHERE ((make='$make' AND type='$type') AND Categories like '%$Categories%') || (make ='$make' AND Categories like '%$Categories%'))";

 

nope... the first categories had 2 )'s... where it only shoulda had one, and should be at the end

ok, This is my new code:


$query="SELECT * FROM business_info WHERE ((make='$make' AND type='$type') AND Categories like '%$Categories%') || (make ='$make' AND Categories like '%$Categories%'))";

 

and here is my display


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

ok this one is working

 

$query="SELECT * FROM business_info WHERE ((make='$make' AND type='$type' AND Categories like '%$Categories%') || (make ='$make' AND Categories like '%$Categories%'))";

 

the only problem is that is selecting the whole database basicly is doing the last statement

 

(make ='$make' AND Categories like '%$Categories%'))";

 

 

Archived

This topic is now archived and is closed to further replies.

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