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

Kevv3

New Member
Messages
30
Reaction score
0
Points
0
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
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
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:

Kevv3

New Member
Messages
30
Reaction score
0
Points
0
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:
Top