Results 1 to 4 of 4

Thread: mysql query in php

  1. #1

    Thread Starter
    Fanatic Member noielen's Avatar
    Join Date
    Nov 2005
    Location
    Cebu, Phil.
    Posts
    680

    Red face mysql query in php

    hi everyone,

    i have a msyql database with 1 table (almost 2,000 records) for now. one of the fields of this table is 'cost'. i want a query that results, like the ff:

    Cost
    2,000 to 3,000
    4,000 to 6,000
    7,000 to 12,000
    .
    .
    .
    greater than 20,000

    this is for my search option list. is it possible? a query that returns like this? maybe, except for the last one line.

    any help really appreciated...
    noister
    <advertising link removed by moderator>

  2. #2
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Godzone, oops Oz
    Posts
    355

    Re: mysql query in php

    Not an expert.

    But would imagine you can either do multiple SQL statements, apparently a bad thing, or use the "ORDER BY cost" to sort the records then use a switch statement to process them individually in php script.

  3. #3
    New Member
    Join Date
    Feb 2008
    Posts
    5

    Re: mysql query in php

    So you want to select things, ONLY if they are a certain amout?
    Try this (untested):
    Code:
    $sql = "SELECT * FROM `table` WHERE `price` >= 20000;";
    $query = mysql_query($sql, $link)
        or die("Error; " . mysql_error());

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: mysql query in php

    Code:
    SELECT count(id), FLOOR(value/1000)*1000 calc FROM test1 GROUP BY calc;
    SELECT value, FLOOR(value/1000)*1000 calc FROM test1 ORDER BY value;
    A simple reduction function on the value can sort them out into any ranges you like. Just remember the calc column will contain the lower bound of your range and no value will appear for a range if there are no values within the range.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width