• We should now be fully online following an overnight outage. Apologies for any inconvenience, we do not expect there to be any further issues.

Possible to tell php only to check first two digits of entry ?

Smolek

Diamond Member
Aug 30, 2001
4,985
1
0
I have a piece of code that im working and had a question on a spot. I have a certain section that if the db has one set of numbers, it displays one link. If it displays another code, it shows a different link.

The problem I have is now other then the first two digits each code will be different and was wondering if there was any type of "starts with" or "AB***" code that tells the script to only look at the first two letter when checking a db ?

Example;

DB Entry: AB1234567890123456 => http://www.test.com

or

DB Entry ZY12345678979879879 => http://www.example.com
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Use LIKE

For example
SELECT FROM table WHERE field LIKE 'AB%'

% Is the wild card, but it doesn't limit the amount of characters after it. If you know the exact number, you can also use an underscore ( _ ) to mark off each wildcard character it will match.

And this isn't the PHP code that handles this (though you could do it in PHP, but it would be more work and more of a toll on your script), it's the database.

http://www.htmlite.com/mysql011.php