KurveMedia Posted July 6, 2008 Share Posted July 6, 2008 I have searched the forums for a post that dealt with my question, but couldn't find one. My question is: I have a search form that needs to look for records in a mysql database. what i want is it to look for records using both fields as the criteria and to display. I have it working using one field, but not sure how i go about using both fields. below is the php code that i have at the moment. I'm using dreamweaver for my code. $colname_rsListing = "-1"; if (isset($_GET['category'])) { $colname_rsListing = $_GET['category']; } mysql_select_db($database_MscottLinx, $MscottLinx); $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s", GetSQLValueString($colname_rsListing, "text")); $rsListing = mysql_query($query_rsListing, $MscottLinx) or die(mysql_error()); $row_rsListing = mysql_fetch_assoc($rsListing); $totalRows_rsListing = mysql_num_rows($rsListing); if anybody knows of a post here in the forums that could help me out, could you please point me to that post if you need any more info please let me know Mike Kurve Media Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Just use AND in the WHERE clause. SELECT * FROM sometable WHERE somecolumn=$id AND anothercol = $name; But use your values and info. =P Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 6, 2008 Author Share Posted July 6, 2008 DarkWater, thanks for the quick reply Would the code below be correct? $colname_rsListing = "-1"; if (isset($_GET['category'])) { $colname_rsListing = $_GET['category']; $colname_rsListing2 = $_GET['zip']; } mysql_select_db($database_MscottLinx, $MscottLinx); $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s", GetSQLValueString($colname_rsListing, "text") AND BusinessZip = %s", GetSQLValueString($colname_rsListing2, "text")); $rsListing = mysql_query($query_rsListing, $MscottLinx) or die(mysql_error()); $row_rsListing = mysql_fetch_assoc($rsListing); $totalRows_rsListing = mysql_num_rows($rsListing); Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 No. Try: $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s AND BusinessZip = %s", GetSQLValueString($colname_rsListing, "text"), GetSQLValueString($colname_rsListing2, "text")); Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 6, 2008 Author Share Posted July 6, 2008 ok i'll try that. I'll let ya know what results i get . thanks Mike Kurve Media Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 Woops, I lied. Use: $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = '%s' AND BusinessZip = '%s'", GetSQLValueString($colname_rsListing, "text"), GetSQLValueString($colname_rsListing2, "text")); Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 6, 2008 Author Share Posted July 6, 2008 wow im getting i guess it would be considered an error, never seen this kind before. "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 'Alimentos y Bebidas '' AND BusinessZip = ''85335''' at line 1" not sure what that's all about, here is my php code $colname_rsListing = "-1"; if (isset($_GET['category'])) { $colname_rsListing = $_GET['category']; $colname_rsListing2 = $_GET['zip']; } mysql_select_db($database_MscottLinx, $MscottLinx); $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = '%s' AND BusinessZip = '%s'", GetSQLValueString($colname_rsListing, "text"), GetSQLValueString($colname_rsListing2, "text")); $rsListing = mysql_query($query_rsListing, $MscottLinx) or die(mysql_error()); $row_rsListing = mysql_fetch_assoc($rsListing); $totalRows_rsListing = mysql_num_rows($rsListing); Mike Kurve Media Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 This is the exact reason why I hate programs that code for you. Change the query to: "SELECT * FROM listings WHERE MainCat = %s AND BusinessZip = %s" Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 6, 2008 Share Posted July 6, 2008 holy hell thats some messy looking code, please stop using dreamweaver for php, use it to make the html, then code the php with notepad or something. Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 6, 2008 Author Share Posted July 6, 2008 DarkWater Ok, no error, but nothing is pulling up. any ideas? gigas10 yeah i know, but i don't do php work that much, so that's the reason im not hand coding it. Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 6, 2008 Share Posted July 6, 2008 $row_rsListing = mysql_fetch_assoc($query_rsListing); $totalRows_rsListing = mysql_num_rows($query_rsListing); I think you didnt call your query correctly. Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 6, 2008 Author Share Posted July 6, 2008 Ok, now this is getting aggravating and i can now understand, why people don't like for Dreamweaver to code php. I think my best bet would to, just scrap the php coded by dreamweaver and code it by hand. thing is im not sure were to start....lol sad i know... Quote Link to comment Share on other sites More sharing options...
gigas10 Posted July 6, 2008 Share Posted July 6, 2008 Did that not work? I was pretty sure that was your problem. Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 6, 2008 Author Share Posted July 6, 2008 gigas10 I'm not sure what was wrong with it. I'm not that great at php, hence the reason i'm using dreamweaver for it. sorry... here is my entire php code: <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_rsListing = "-1"; if (isset($_GET['category'])) { $colname_rsListing = $_GET['category']; $colname_rsListing2 = $_GET['zip']; } mysql_select_db($database_MscottLinx, $MscottLinx); $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s AND BusinessZip = %s", GetSQLValueString($colname_rsListing, "text"), GetSQLValueString($colname_rsListing2, "text")); $rsListing = mysql_query($query_rsListing, $MscottLinx) or die(mysql_error()); $row_rsListing = mysql_fetch_assoc($rsListing); $totalRows_rsListing = mysql_num_rows($rsListing); ?> Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 7, 2008 Author Share Posted July 7, 2008 Just friendly bump Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 Hey, sorry about not helping you finish yesterday. =P Is BusinessZip a number? If so... $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s AND BusinessZip = %s", GetSQLValueString($colname_rsListing, "text"), GetSQLValueString($colname_rsListing2, "text")); Change it to: $query_rsListing = sprintf("SELECT * FROM listings WHERE MainCat = %s AND BusinessZip = %d", GetSQLValueString($colname_rsListing, "text"), GetSQLValueString($colname_rsListing2, "int")); Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 7, 2008 Author Share Posted July 7, 2008 yeah its a number, i will try that and let you know, thanks for the help, i really appreciate it... do you freelance? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 7, 2008 Share Posted July 7, 2008 Yes, I do. Contact me via PM so that the mods don't move/lock the topic. Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 7, 2008 Author Share Posted July 7, 2008 Ok def will Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 9, 2008 Author Share Posted July 9, 2008 DarkWater still nothing... check your PM Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 12, 2008 Author Share Posted July 12, 2008 Darkwater, you around? Quote Link to comment Share on other sites More sharing options...
KurveMedia Posted July 15, 2008 Author Share Posted July 15, 2008 Any Help would be great, still having trouble with this. Thanks in advance. Mike 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.