Jump to content

QUERY - Ignore letters


Canman2005

Recommended Posts

not efficient, bit would work

 

<?php

$result = "132HS3G";
$numbers = array('1', '2', '3', '4');
$filter = array('', '', '', '');
$cleaned = str_ireplace($numbers, $filter, $result);

echo $cleaned;

?>

 

The code above would echo HSG

 

You would need to create a numeric value for each number in the numbers and a corresponding blank value in the $filter.

Link to comment
https://forums.phpfreaks.com/topic/64011-query-ignore-letters/#findComment-319086
Share on other sites

Is there now way of doing a

 

SELECT * FROM `table` ORDER BY `code` DESC

 

But ignore letters in the code field.

 

Basically I have tons of codes with different letters at the start of each code, I want to get a print out of all the codes, highest to lowest, despite what the letters are

Link to comment
https://forums.phpfreaks.com/topic/64011-query-ignore-letters/#findComment-319091
Share on other sites

ok try this SQL has a string function like php so you can manipulate the string before ouput that compltely

 

somethinglike

 

SELECT putstringfunctionhere(the field ) as key FROM `table` ORDER BY `key` DESC

 

try to search on mysql the string function and sure you can do this

Link to comment
https://forums.phpfreaks.com/topic/64011-query-ignore-letters/#findComment-319105
Share on other sites

i cant remember that string manipulation in sql because i do that in my school days bu you have to replace the character and put leave only the letter it actually work just the same in php

 

but you cant get it odered by but having the php array_sort() it will sort your array by once no need for looping

 

putstringfunctionhere
[code]

what i mean by that is for you to look an appropriate sql string function  

[/code]

Link to comment
https://forums.phpfreaks.com/topic/64011-query-ignore-letters/#findComment-319109
Share on other sites

try ds ,

 

SELECT  cast(reverse(abs(reverse(Code_Field))) as unsigned)  as Code as key FROM `table` ORDER BY Code DESC

 

canman2005, i am hoping dat all ur codes are like ds in format

    D02434

    EF02123

    N4576

i mean letters first followed by numbers

no

  02434D

  2124FE45

coz ds will work only with ds format...

hope ds will help

Link to comment
https://forums.phpfreaks.com/topic/64011-query-ignore-letters/#findComment-319149
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.