Forum Moderators: coopster
in the database they are 86,87 etc. so did:
$ID = $result['ID'] + 10000
echo "VA".$ID
my question is how can i get it back to just 86,87 from a search form to get a query i want?
i want item.php?id=VA10086
but to get database it needs to be
select * from database where id=86
how do i remove the VA bit? cos i can then do -10000
cheers.
$ID = 'VA10089';
$id_no = 1 * substr($ID, - 4);
This will extract the last 4 digits. The 1 * ... part removes the front zeroes if they exist to just return
89
-------------------
If the string is variable size such as
VA1025
VA100020087
then the above will not work. In this case if the VA1 is consistent (i.e. you don't have VB10002, XY80023) then just replace that string with blank
$id_no = 1 * str_replace('VA1', '', $ID);
or if VA1 is not consistent in character but is in length (i.e. 2 letters, 1 character VB2 XY7) then try this:
$id_no = 1 * substr($ID, 3);
This will extract the part of the string after the first 3 chars.