Steveinid Posted August 27, 2022 Share Posted August 27, 2022 I have a database with prices. I am displaying all prices from lowest to highest. Not all products in the database are updated with prices so by default they show $0.00 and updated products show their actual price like $5.49 for example. I have set it so that it will show the price as 'Not Updated' if the price is actually 0.00. (See code below) However numerically it is still 0.00 as far as the 'ORDER by' command is concerned. if ($row["current_price"] === 0.00 ) { echo "<span style='font-size:85%;'>" . $row['product_name'] . "</span>" . " - " . "<span style='color: red'>" . "<span style='font-size:70%;'>Not Updated</span>" . "</span><br>"; I want to order it so that all products with prices that = 0.00 are posted after products with actual prices but still showing the lowest price first so it would look as follows: product 1 = $2.99 product 2 = $3.29 product 3 = Not Updated My work around is to actually make all prices by default a very high price of 50,000 for example (since no price in the database will be that high for any of the products) then I change the above code to : if ($row["current_price"] > 49999.99) { echo "<span style='font-size:85%;'>" . $row['product_name'] . "</span>" . " - " . "<span style='color: red'>" . "<span style='font-size:70%;'>Not Updated</span>" . "</span><br>"; ...and this works fine as far as a visitor is concerned but I don't like that I've had to do that. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/315244-how-to-display-data-after-retreiving-it-with-order-by-in-a-select-query/ Share on other sites More sharing options...
Barand Posted August 27, 2022 Share Posted August 27, 2022 ORDER BY current_price = 0, current_price A boolean condition returns 0 or 1 (true) Quote Link to comment https://forums.phpfreaks.com/topic/315244-how-to-display-data-after-retreiving-it-with-order-by-in-a-select-query/#findComment-1599885 Share on other sites More sharing options...
Steveinid Posted August 27, 2022 Author Share Posted August 27, 2022 20 minutes ago, Barand said: ORDER BY current_price = 0, current_price Thank you... worked great. Quote Link to comment https://forums.phpfreaks.com/topic/315244-how-to-display-data-after-retreiving-it-with-order-by-in-a-select-query/#findComment-1599887 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.