Jump to content


Photo

Help with 'strlen' script


  • Please log in to reply
3 replies to this topic

#1 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 20 May 2006 - 12:08 AM

I am working on a site for an auto dealership where users can search based on certain criteria, one of which is the VIN number.

I have this one input:
if($_POST['vin']) {$where[] = "vin = '{$_POST['vin']}'";}
which works with the search script I was able to hack together, but what I want to do is also have the ability to search by the last 6 of the VIN. Meaning if a user enters all 17 alpha-numeric characters it returns a result, and as well if they only enter the last 6 characters of the vin...

Does anyone have any idea how I can go about this?

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 20 May 2006 - 12:12 AM

$last_six = substr($_POST['vin'], -6);

Legend has it that reading the manual never killed anyone.
My site

#3 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 20 May 2006 - 12:36 AM

[!--quoteo(post=375398:date=May 19 2006, 08:12 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 19 2006, 08:12 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$last_six = substr($_POST['vin'], -6);
[/quote]

I don't get it! How do I make it work based on the example I posted?

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result


#4 roxanerinard

roxanerinard
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 20 May 2006 - 05:00 AM

That should give you the last six numbers of the vin they are requesting. Then you could try iterating through the table and compare the last six numbers of every entry or try the LIKE operator in SQL (not sure if that would work).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users