tags:

views:

41

answers:

2
$test2=mysql_query("SELECT min(substr(status,1) FROM railways");
while($test_array1=mysql_fetch_array($test2)){
echo "<pre>";
print_r($test_array1);
echo "</pre>"; 
}

what is the correct form of this query...need to get the min value from the table itself..

+1  A: 

Hi Sachindra,

substr(status, 1) returns the string as it is ... mysql counts in strings from 1, not from 0.

if i got you right using substr(status,2) is what you are looking for.

best regards phil

Philipp Andre
donno y but substr(status, 1) gives the numeric values for me. substr(status, 0) gives the entire string as it is.. is it a matter of the version used??? i m not sure
Sachindra
i'm using mysql 5.1 and substr(status, 0) returns an empty string. which version are you running?since you extract the numeric value correctly, what is your difficulty now?btw: why do you use a loop to print out the results? min(..) returns a single value.
Philipp Andre
A: 

substr(status, 1) is going to give 'w21', but substr(status, 2) is going to give 21. If you want to get the minimum and the pattern is DIGIT_NUMBER_NUMBER, you will use min(substr(status, 2)). From this data set: w21, c33, d55, d11, it will pull the minimum number you want.

Freebytes
hello, echo ;-)
Philipp Andre