SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select the lowest and highest value

    Hi All

    I am making a website that will sell shirts. A shirt might be one style but in many colours and sizes and prices.

    e.g.

    Product is V neck shirt

    Stock is S - Blue - $19.99, M - Green - $22.99, Large - White - $25.99 etc

    I am going to have an image of the shirt with the name of the shirt under (V neck shirt) and then the price range under that ($19.99 to $25.99)

    I haven't done this before and have been doing some research but am now stuck.

    Here is my code so far:

    PHP Code:
    $content=mysql_query("SELECT MAX(price) AS max_price, MIN(price) AS min_price FROM shirts");
      
      
    $content mysql_fetch_array($content);
      
    $max_price $content['max_price'];
      
    $min_price $content['min_price'];
      
      echo    (
    "$min_price - $max_price"); 
    I know that at the moment my lowest is 19.99 and highest is 109.00 but when I run this code I get lowest is 58.99 and highest is 100.00.

    What am I doing wrong?

    Any help would be great.

    Many Thanks

    mrmbarnes

  2. #2
    SitePoint Member
    Join Date
    Dec 2004
    Location
    oklahoma
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to change your price column data type to DECIMAL(10,2) instead of varchar or whatever data type you have it set to right now and then your query will work correctly.

  3. #3
    SitePoint Evangelist
    Join Date
    Nov 2003
    Location
    Brisbane, Australia
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's it! Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •