aebstract Posted April 17, 2008 Share Posted April 17, 2008 So in my search feature, I have an "Order by" part, where the user can choose how they want their results to display. One of the options is to order the results by price, which it does.. though the prices will list as such: 199.89 230.45 256.99 26.55 289.65 3.56 345.88 So it's going down in order, somewhat. It's just I need it to order by it's actual value, 3.56 should be at the top. My query looks like this: $result2 = mysql_query("SELECT * FROM parts WHERE $searchfor LIKE '%$partsearch%' ORDER BY $orderby") or DIE(mysql_error()); Hopefully there is an easy workaround for this. Thanks Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/ Share on other sites More sharing options...
AndyB Posted April 17, 2008 Share Posted April 17, 2008 and are those values numbers or strings? Looks like you're using the wrong field type because those results are correctly sorted as strings. Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/#findComment-519562 Share on other sites More sharing options...
aebstract Posted April 17, 2008 Author Share Posted April 17, 2008 Yes, you're right and I do realize it is displaying them correctly for that method. How can I fix it so that they are numbers vs being strings? Right now they are "tinytext" in db, should be changed to? Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/#findComment-519564 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Set it to float, length 6,2 (gives you 6 before decimal, 2 after) Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/#findComment-519566 Share on other sites More sharing options...
conker87 Posted April 17, 2008 Share Posted April 17, 2008 Uhm, Numeric? I'm not sure, since that's stored in binary. Same goes for Decimal. Try em and see Or what the dancing matt says. Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/#findComment-519569 Share on other sites More sharing options...
PFMaBiSmAd Posted April 17, 2008 Share Posted April 17, 2008 You should use DECIMAL data type, not float. A float data type will have floating point conversion errors. Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/#findComment-519760 Share on other sites More sharing options...
aebstract Posted April 17, 2008 Author Share Posted April 17, 2008 Got it working Thanks guys, was having trouble converting over but realized I just had to set the size to 10,2 and it would keep my decimal place from my old column. Thanks again Link to comment https://forums.phpfreaks.com/topic/101577-solved-order-by-price-not-exactly-right/#findComment-519808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.