Whizzell Posted July 28, 2009 Share Posted July 28, 2009 i need to select * from table where id or parent category = $_GET['cat'] but then select all the records from my listings table if its category matches one that i pulled from the cats table with the above sql. Anyone able to help with the code? I Have this so far if(isset($_GET['cat'])) $listwhere = "WHERE cat = ".$_GET['cat']." "; if(!isset($_GET['cat'])) $listwhere = ""; $result = mysql_query("SELECT * FROM listings ".$listwhere."ORDER BY updated DESC"); This works fine for just the records in the category etc but it doesn't show all the listings in the subcategories lower down too which i need it too. Any help welcome. Will. Link to comment https://forums.phpfreaks.com/topic/167727-select-from-table-where-id-x-or-other_id-x/ Share on other sites More sharing options...
lonewolf217 Posted July 28, 2009 Share Posted July 28, 2009 i think you will have to go into more detail about how the subcategories fit into this . are they in the same table with the categories ? Link to comment https://forums.phpfreaks.com/topic/167727-select-from-table-where-id-x-or-other_id-x/#findComment-884502 Share on other sites More sharing options...
Whizzell Posted July 28, 2009 Author Share Posted July 28, 2009 Category table structure is as follows: catid int(11) catorder int(11) suborder int(11) level int(11) parentid int(11) name varchar(255) desc text Then the listings table is as follows: id int(9) cat int(9) title varchar(75) link mediumtext desc longtext img int(1) votes int(9) rating int(9) limited int(1) exclusive int(1) tested int(1) free int(1) updated timestamp expires date affvalue decimal(3,2) affref int(9) I'm sure both my tables could be improved aswell, i'm quite new to PHP and Mysql so all help apprieciated i think you will have to go into more detail about how the subcategories fit into this . are they in the same table with the categories ? Link to comment https://forums.phpfreaks.com/topic/167727-select-from-table-where-id-x-or-other_id-x/#findComment-884519 Share on other sites More sharing options...
lonewolf217 Posted July 28, 2009 Share Posted July 28, 2009 okay, but which field is the "subcategory" that you want, and why do you think it isn't showing ? There is no column in the listings table that looks like it refers to a subcategory. Your query right now looks like it pulls everything from the listings table with a certain category ID, is it expected to do something else ? Link to comment https://forums.phpfreaks.com/topic/167727-select-from-table-where-id-x-or-other_id-x/#findComment-884523 Share on other sites More sharing options...
Whizzell Posted July 28, 2009 Author Share Posted July 28, 2009 ye, i need to modify it so it also pulls the listings with the category id of all the categories that have a parentid of $_GET['cat'] I only know how to pull data out of one recordset at a time etc. So i'm lost getting the other listings. Link to comment https://forums.phpfreaks.com/topic/167727-select-from-table-where-id-x-or-other_id-x/#findComment-884524 Share on other sites More sharing options...
Whizzell Posted July 28, 2009 Author Share Posted July 28, 2009 I think its possible to do it all inside one SQL query i think, something roughly along the lines of "Select * from categories where catid = $cat or parentid = $cat (Select * from listings where cat = $result)" I know this won't work at all but i've tried a few variations on this using snippets from other forums and tutorials and just can;t get the syntax right. Link to comment https://forums.phpfreaks.com/topic/167727-select-from-table-where-id-x-or-other_id-x/#findComment-884536 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.