emaxads Posted February 2, 2009 Share Posted February 2, 2009 It looks like this is the place to be for php and MySQL i have spent a lot of time reading your forums but have not figured out the ins and outs of SQL syntax. I am trying to make a directory script work for me on more than one site using one data base. I want each site to be able to display its unique links as well as common for all. I added a site_id Field on the existing data table in question that will have Varchar allsites, site1, site2 etc the site_id is defined in config unless changed when submited to table. I am using SQL Server version: 5.0.27-standard The Script I am working on is from IndexScript and its a bit rough even for my limited abilities but what i need is the following to output rows with cat_id = same and site_id = allsites and site1 $sql = "select title, description, url, " . "dl_owner, dl_url_1, dl_url_2, dl_url_3, dl_url_4, dl_url_5 " . "from dir_url where cat_id = " . fnpreparesql($_GET['cat_id']) . " and " . "site_id = 'allsites' " . " or " . "site_id = ('$emaxsite') " ; No errors to report but what i get is all site1 and allsites but i also get all cat_id's I tried many different variations and tryed to create array as explained in this forum but no luck. Here is the Table structure for table `dir_url CREATE TABLE `dir_url` ( `cat_id` int(11) NOT NULL default '0', `site_id` varchar(20) NOT NULL, `url` varchar(255) NOT NULL, `title` varchar(75) NOT NULL, `description` varchar(900) NOT NULL, `keywords` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, `recip_url` varchar(255) NOT NULL, `dl_owner` varchar(100) NOT NULL, `dl_url_1` varchar(255) NOT NULL, `dl_url_2` varchar(255) NOT NULL, `dl_url_3` varchar(255) NOT NULL, `dl_url_4` varchar(255) NOT NULL, `dl_url_5` varchar(255) NOT NULL, `ip` varchar(20) NOT NULL, `date` date NOT NULL default '0000-00-00', `featured` char(1) NOT NULL, KEY `keywords` (`keywords`), KEY `url` (`url`), KEY `featured` (`featured`), KEY `cat_id` (`cat_id`), KEY `title` (`title`), KEY `date` (`date`), KEY `description` (`description`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; This is probably a no brainer for most you freaks but i have never done much with SQL than back up and create Any help would be greatly appreciated Its going to take me long enough to make the Index Script XHTML compliant to match the sites i want to use it on making this work will be a great help. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 2, 2009 Share Posted February 2, 2009 Look at conditions you've put in your query WHERE cat_id = 1 AND site_id = 'allsites' OR site_id = '1' MySQL evaluates AND's and OR's just like boolean logic teaches us. Which is: 1: get all records that satisfy 'cat_id = 1 AND site_id = 'allsites'' 2: also get all records that satisfy 'site_id = 1' Add a couple of parentheses, and you shuld get result as you want them WHERE cat_id = 1 AND (site_id = 'allsites' OR site_id = '1') 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.