''ORDER BY'' is not working ...any help!

Discussion in 'MySQL' started by php-lover, Oct 8, 2006.

  1. #1
    Need help!..I am trying to run my query but it's not work... here is my code.

    "SELECT * FROM name ORDER BY fname ASC"

    Sort is not working....but I know the problem, I don't know how to solve.

    The problem is ....there is a single quote inside the fname like 'Oliver and that's why the ORDER BY is not working ...

    Any help..
     
    php-lover, Oct 8, 2006 IP
  2. czSellers

    czSellers Peon

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please post structure of table name
     
    czSellers, Oct 8, 2006 IP
  3. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So, what you want it to do is ignore the quote if there's one, right?
    I guess you need the quote to be there for some reason, otherwise you'd be asking "how do I remove the quote?".
    Mmm... tricky, I can't think of a solution that's pure SQL, but if you can import the result into Excel or manipulate it with PHP I think there's a way to do it.
     
    rb3m, Oct 8, 2006 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    mysql> use customer;
    Database changed
    mysql> desc cust_name;
    +-------+----------+------+-----+---------+----------------+
    | Field | Type | Null | Key | Default | Extra |
    +-------+----------+------+-----+---------+----------------+
    | id | int(11) | NO | PRI | | auto_increment |
    | fname | char(20) | NO | | | |
    | lname | char(20) | NO | | | |
    +-------+----------+------+-----+---------+----------------+
    3 rows in set (0.00 sec)

    mysql>


    Here is my query: "SELECT fname,lname FROM cust_name ORDER BY fname ASC"
     
    php-lover, Oct 8, 2006 IP
  5. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Yes rb3m..I am looking for are way to escape the single quote not remove.

    I try to sort the result using sort() in PHP but I can't, because I am using

    while($row = mysql_fetch_array($result)){
    echo $row['fname'].' '.$row['lname'];
    }


    I am thinking about using this code in PHP to sort the array.

    $custname = mysql_fetch_array($result);
    $row = sort($custname);

    foreach($row as $fname=>$lname){
    echo $fname.' '.$lname;
    }


    But sorry guys, the thing I am looking for is there any way to escape the single quote in mysql query to make "ORDER BY" work.
     
    php-lover, Oct 8, 2006 IP
  6. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #6
    Try using this

    "SELECT * FROM name ORDER BY REPLACE(fname,'\'','') ASC"
    Code (markup):
     
    harsh789, Oct 9, 2006 IP
  7. aRo`

    aRo` Peon

    Messages:
    141
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    are you sure it's the "name" table ?

    desc cust_name;
    Code (markup):
     
    aRo`, Oct 9, 2006 IP
  8. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #8
    harsh789 thanx for the help and it's work ...good job mann
    and I just want to say thanx to all of you guys for helping me... the answer for my problem is in harsh789 comment...:)
     
    php-lover, Oct 9, 2006 IP
  9. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Cool! I didn't know SQL had that instruction.
     
    rb3m, Oct 9, 2006 IP