Jump to content

How to display data after retreiving it with "ORDER by" in a select query


Steveinid

Recommended Posts

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:

  1. product 1 = $2.99
  2. product 2 = $3.29
  3. 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.