e1seix Posted September 10, 2007 Share Posted September 10, 2007 i seem to be having a lot of difficulties using this feature. What i want to do is "GET" the category from title bar to use with my query. the weird thing is. when the value of 'category' is written text like the word "aftershave" it comes up with --unknown column 'aftershave' in 'where clause' however this does work when the value is a numeric sequence like "2007" is there some clause or something i have to declare to change this? it's driving me crazy! lol Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/ Share on other sites More sharing options...
Fadion Posted September 10, 2007 Share Posted September 10, 2007 What type of char is the category column? EDIT: I mean is it an INT? Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/#findComment-345129 Share on other sites More sharing options...
teng84 Posted September 10, 2007 Share Posted September 10, 2007 --unknown column <-- sometimes when you query and u use wrong data types that is what youre going to have eg. if the field is int then you access them with using string then that might happen does it make sense if not give some example Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/#findComment-345131 Share on other sites More sharing options...
e1seix Posted September 10, 2007 Author Share Posted September 10, 2007 it's a varchar which is why i'm confused Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/#findComment-345133 Share on other sites More sharing options...
jitesh Posted September 10, 2007 Share Posted September 10, 2007 if(isset($_GET['category']) and !empty($_GET['category']) and is_integer($_GET['category'])){ $sql = "select * from product where category = ".$_GET['category']; ................. ................ }else{ echo "Invalid input for category"; } Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/#findComment-345135 Share on other sites More sharing options...
e1seix Posted September 10, 2007 Author Share Posted September 10, 2007 how exactly would i integrate that into the following code? lol. know i'm taking the long way around by the way... $limit=20; $startrow = $_GET['startrow']; $qry = mysql_query("SELECT * FROM fragrances WHERE fragrances.avail='true' AND fragrances.browse='.$_GET[browse].' UNION SELECT * FROM skincare WHERE skincare.avail='true' AND skincare.browse='.$_GET[browse].' UNION SELECT * FROM shaving WHERE shaving.avail='true' AND shaving.browse='.$_GET[browse].' UNION SELECT * FROM bodycare WHERE bodycare.avail='true' AND bodycare.browse='.$_GET[browse].' UNION SELECT * FROM haircare WHERE haircare.avail='true' AND haircare.browse='.$_GET[browse].' UNION SELECT * FROM suncare WHERE suncare.avail='true' AND suncare.browse='.$_GET[browse].' ORDER BY title LIMIT $startrow, $limit")or die(mysql_error()); PS. you need to imagine the 'browse' is actually the 'category' Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/#findComment-345142 Share on other sites More sharing options...
jitesh Posted September 10, 2007 Share Posted September 10, 2007 First of all you have multiple table with your product so this is not a proper normalize data. You may follow like this table 1 : Master products items product_item_id product_item_name 1 fragrances 2 skincare 3 shaving table 2 : Product table product_id product_item_id product_name avail browse 1 1 (fragrances) prd1 true 1 2 1 (fragrances) prd2 true 1 3 2 (skincare) prd3 true 2 So for above case you have only one query if(isset($_GET['browse']) and !empty($_GET['browse']) and is_integer($_GET['browse'])){ select * from product where avail = 'true' and browse = '"$_GET['browse']."'"; }else{ echo "Invalid input for browse"; } Quote Link to comment https://forums.phpfreaks.com/topic/68656-_get-query/#findComment-345151 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.