franknu Posted May 11, 2007 Share Posted May 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/ Share on other sites More sharing options...
taith Posted May 11, 2007 Share Posted May 11, 2007 somin like this... $query="SELECT * FROM business_info WHERE ((make=\"$make\" AND type=\"$type\") ||(make =\"$make\" AND Categories like \"%$Categories%\"))AND Categories LIKE \"%$Categories%\" "; Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250582 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 ok that works my problem now is this some of the this are repeating how can i tell that if they are already there show only once. any peace of advise Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250591 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 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%\") \" "; Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250600 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250604 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 ok I keep gettin the same error 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 Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250618 Share on other sites More sharing options...
per1os Posted May 11, 2007 Share Posted May 11, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250642 Share on other sites More sharing options...
taith Posted May 11, 2007 Share Posted May 11, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250654 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250671 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 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%'))"; Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250674 Share on other sites More sharing options...
taith Posted May 11, 2007 Share Posted May 11, 2007 which would just be a logic issue... first one grabs limits by type... second one doesnt... Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250689 Share on other sites More sharing options...
sasa Posted May 11, 2007 Share Posted May 11, 2007 if you try to use typo criteria only if $typo !='' $query="SELECT * FROM business_info WHERE make='$make' AND (type='$type' OR ''='$type') AND Categories like '%$Categories%'" Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250699 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 it is not giving me any results for make so if i only select make it doest get me any results Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250713 Share on other sites More sharing options...
franknu Posted May 11, 2007 Author Share Posted May 11, 2007 works great now so my only problem is that it is repeating certain things because it is finding an in diffrent type so how can i tell it so if something show us up only repeat once Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250722 Share on other sites More sharing options...
taith Posted May 11, 2007 Share Posted May 11, 2007 you'd need to use group by and distinct()... i'd explain it... but i'm a bit rushed at the moment :-) Quote Link to comment https://forums.phpfreaks.com/topic/50942-can-i-double-query-in-the-sale-loop/#findComment-250725 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.