+ Reply to Thread
Results 1 to 3 of 3

Thread: order by substr(..) ???howdo??

  1. #1
    Kevv3 is offline x10Hosting Member Kevv3 is an unknown quantity at this point
    Join Date
    Apr 2006
    Posts
    15

    order by substr(..) ???howdo??

    I have a problem with mySQL

    Consider I have a table with a column named member_functions.
    One record = 10233435

    In the table functions, I gave every record a number from 10 to 40 so in the record I need everytime 2 characters to compare with my table functions to get the propre functions for that member.
    example: 10233435 = function 10 + function 23 + function 34 + function 35

    that's never been a problem to get that, but I want to order my records by the first 2 characters of every record: this is what I have :

    4 $result = mysql_query("select * from members order by substr(member_functions,2) asc");
    5 while($myrow = mysql_fetch_array($result))
    6 {
    7 echo("<table width='360' border='0' cellspacing='0' cellpadding='0'>
    .....
    and this is the error:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
    /backup/home/kevv3/public_html/gezinsbond/bestuur.php on line 5

    I allready figured out that it has to do something with the order by substr(...)

    can someone plss help me, it's urgent

  2. #2
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: order by substr(..) ???howdo??

    I do not believe you can use substr() (Your talking about the PHP function, correct?) in a MySQL query.

    I believe this is why your getting the "not a valid MySQL resource" from mysql_fetch_array(). If you place "or die(mysql_error());" at the end of your mysql_query(), I'm sure you will get an error with the substr() in the query.

    So.. I want to help you with your problem, but I'm a little confused exactly what it is your trying to do.

    You have a table, and in that table the column `member_functions`. I understand that. What I don't get is what the column contains. Does the value in a row, under that column, have (For example) the value "12345678"? Or is that multiples row's values (Records?) all smushed together?

    Also, are there multiple rows you want to do this with, or only one?

    I get what you want to do, but unsure of the specifics. After you post back I'll help you out more.
    Last edited by Bryon; 05-02-2006 at 04:27 PM.

  3. #3
    Kevv3 is offline x10Hosting Member Kevv3 is an unknown quantity at this point
    Join Date
    Apr 2006
    Posts
    15

    Re: order by substr(..) ???howdo??

    it's like this:

    table functions:
    func_nr colomn func:
    10 crewmember
    12 bigboss
    13 barman
    14 member
    ...........

    and a table members
    columns : member_nr, member_nm,... and member_function
    1 george 101314
    2 james 1214

    so I want to sort it at the two first characters from member_function

    in that way, george will be the first on my screen because his first function is higher ranked (10 vs. 12). It works on my computer, but not on the net. maybe older version????
    Last edited by Kevv3; 05-03-2006 at 07:17 AM.

+ Reply to Thread

Similar Threads

  1. free hosting order?
    By Spartan Erik in forum Free Hosting
    Replies: 1
    Last Post: 08-09-2005, 12:31 PM
  2. Where do you order computer parts online?
    By FeZ.06.925 in forum Off Topic
    Replies: 3
    Last Post: 05-17-2005, 04:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers