LukePVB Posted February 10, 2013 Share Posted February 10, 2013 I have a listing script that I put together with dreamweaver that lists ads with page title hyperlinked, company name, phone number, page description, website url and company logo. Right now it lists all the items in my database. Id like to narrow this down by limiting the listings to a specific city and catagory. For example oshawa and basement waterpoofing. Iv got 2 major scripts. I;m not sure which one needs to be modified to narrow down my listing so ill include both. <?php require_once('Connections/BIZread.php'); ?><?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $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; } } mysql_select_db($database_BIZread, $BIZread); $query_getListing = "SELECT ads.page_title, ads.company_name, ads.phone_number, ads.address, ads.city, ads.province_state, ads.websiteurl, ads.page_description, ads.image, ads.page_name, ads.catagory FROM ads"; $getListing = mysql_query($query_getListing, $BIZread) or die(mysql_error()); $row_getListing = mysql_fetch_assoc($getListing); $totalRows_getListing = mysql_num_rows($getListing); $query_getListing = "SELECT ads.page_title, ads.company_name, ads.phone_number, ads.address, ads.city, ads.province_state, ads.websiteurl, ads.page_description, ads.image, ads.page_name, ads.catagory FROM ads"; $getListing = mysql_query($query_getListing, $BIZread) or die(mysql_error()); $row_getListing = mysql_fetch_assoc($getListing); $totalRows_getListing = mysql_num_rows($getListing); ?> and <?php do { ?> <div id="listing"> <div id="pageTitle"> <a href="<?php echo $row_getListing['city']; ?>/<?php echo $row_getListing['catagory']; ?>/<?php echo $row_getListing['page_name']; ?>"><?php echo $row_getListing['page_title']; ?></a></div> <div id="logo"><img src="images/_r12_c8.jpg" width="114" height="57" /></div> <div id="companyName"> <?php echo $row_getListing['company_name']; ?></div> <div id="phoneNumber"> <?php echo $row_getListing['phone_number']; ?></div> <div id="address"> <?php echo $row_getListing['address']; ?>, <?php echo $row_getListing['city']; ?>, <?php echo $row_getListing['province_state']; ?></div> <div id="pageDescription"> <?php echo $row_getListing['page_description']; ?></div> <div id="website"> <?php echo $row_getListing['websiteurl']; ?></div> </div> <?php } while ($row_getListing = mysql_fetch_assoc($getListing)); ?> Any help is appreciated. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2013 Share Posted February 10, 2013 Add a WHERE clause to your SQL. Quote Link to comment Share on other sites More sharing options...
LukePVB Posted February 10, 2013 Author Share Posted February 10, 2013 Add a WHERE clause to your SQL. Could u tell me where that goes exactly and show me an example? im a noobie. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2013 Share Posted February 10, 2013 It's very basic. Find some mysql tutorials, and learn to read the mysql manual. Quote Link to comment Share on other sites More sharing options...
LukePVB Posted February 10, 2013 Author Share Posted February 10, 2013 It's very basic. Find some mysql tutorials, and learn to read the mysql manual. Okay thanks for your help so far. I got the code to work somewhat how i want it to. But i dont know how to add a second WHERE function so it narrows down the listing by two catagories not one. the code i got so far is $query_getListing = "SELECT ads.page_title, ads.company_name, ads.phone_number, ads.address, ads.city, ads.province_state, ads.websiteurl, ads.page_description, ads.image, ads.page_name, ads.catagory FROM ads WHERE City='Oshawa'" Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2013 Share Posted February 10, 2013 Use OR. Quote Link to comment Share on other sites More sharing options...
LukePVB Posted February 10, 2013 Author Share Posted February 10, 2013 Use OR. ty Quote Link to comment Share on other sites More sharing options...
LukePVB Posted February 10, 2013 Author Share Posted February 10, 2013 Use OR. This is not what i'm looking for. This only narrows down the listings by either selecting details that contain a specific city or contain a specific catagory. I'm looking to narrow down the listings to ones that have both the city and the catagory. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2013 Share Posted February 10, 2013 Then use AND. Come on dude. Like I said, basic MySQL tutorials. Quote Link to comment Share on other sites More sharing options...
LukePVB Posted February 10, 2013 Author Share Posted February 10, 2013 Then use AND. Come on dude. Like I said, basic MySQL tutorials. Thanks a lot. 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.