dare87 Posted October 15, 2008 Share Posted October 15, 2008 I have this query: $query="SELECT LotNum, Carat, Color, Clarity, Cert, Meas, Polish, Sym, Price FROM selling_data WHERE Shape='$sp'"; if ($crm==$crx) { $query .= " AND Color='$crm'"; } else { $query .= " AND Color BETWEEN '$crx' AND '$crm'"; } if ($clm==$clx) { $query .= " AND Clarity = '$clm'"; } else { $query .= " AND Clarity BETWEEN '$clm' AND '$clx'"; } if ($ctm>0 && $ctx>0 && $ctm!=$ctx) { $query .= " AND Carat BETWEEN '$ctm' AND '$ctx'"; } elseif ($ctm!='' && $ctm==$ctx) { $query .= " AND Carat='$ctm'"; } elseif ($ctm=='' && $ctx>0) { $query .= " AND Carat <='$ctx'"; } if ($pm>0 && $px>0) { $query .= " AND Price BETWEEN '$pm' AND '$px'"; } elseif ($pm=='' && $px>0) { $query .= " AND Price BETWEEN '1.0' AND '$px'"; } else { $query .= " AND Price > '1'"; } $query .= " ORDER BY Price ASC, Carat, Clarity "; The problem I am having is that Clarity needs to be a number, but in my db it is not. In by db it is Flawless VVS-1 VVS-2 VS-1 VS-2 SI-1 SI-2 SI-3 I-1 I-2 I-3 I need them to equal Flawless = 1 VVS-1 = 2 VVS-2 = 3 VS-1 = 4 VS-2 = 5 SI-1 = 6 SI-2 = 7 SI-3 = 8 I-1 = 9 I-2 = 10 I-3 = 11 How can I do this without changing my db? Thanks Link to comment https://forums.phpfreaks.com/topic/128622-solved-query-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 15, 2008 Share Posted October 15, 2008 This should work with strings as well - http://www.eklekt.com/tutorials/mysql Link to comment https://forums.phpfreaks.com/topic/128622-solved-query-help/#findComment-666625 Share on other sites More sharing options...
dare87 Posted October 16, 2008 Author Share Posted October 16, 2008 I don't understand, could you give me an example please? Link to comment https://forums.phpfreaks.com/topic/128622-solved-query-help/#findComment-666634 Share on other sites More sharing options...
PFMaBiSmAd Posted October 16, 2008 Share Posted October 16, 2008 http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field Link to comment https://forums.phpfreaks.com/topic/128622-solved-query-help/#findComment-666647 Share on other sites More sharing options...
dare87 Posted October 16, 2008 Author Share Posted October 16, 2008 I must be really stupid, I still don't get it. How does that return Flawless as 1? and VVS - 1 as 2? etc... if ($clm==$clx) { $query .= " AND Clarity = '$clm'"; } else { $query .= " AND Clarity BETWEEN '$clm' AND '$clx'"; } This is the part of the code that needs changing. I don't know what to do. Link to comment https://forums.phpfreaks.com/topic/128622-solved-query-help/#findComment-666660 Share on other sites More sharing options...
fenway Posted October 16, 2008 Share Posted October 16, 2008 Try this: SELECT FIELD( Clarity, 'Flawless', 'VVS-1', 'VVS-2', 'VS-1', 'VS-2', 'SI-1', 'SI-2', 'SI-3', 'I-1', 'I-2', 'I-3' ) Link to comment https://forums.phpfreaks.com/topic/128622-solved-query-help/#findComment-667126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.