SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Bloobird's Avatar
    Join Date
    Jan 2005
    Location
    Wales UK
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reading the first 2 digits of a long code

    Hi

    I currently have a system working which reads barcodes(for a stock control system). It all works, but I have been asked to change a few things to make it easier/quicker for the user.
    Each barcode has a 2 digit identifier at the front which is used to identify what type of product it is. eg:
    1249596585736363 - 12 is the identifier and always stays the same on this product.
    I have a product table which contains the product name, description and this 2 digit id.
    I want to be able to scan a barcode in, and compare the first two digits of the barcode to the digits in the product table. I would like the system to then return the appropriate product name(this will then be stored in another table, but im not concerned with that aspect yet).

    At the moment ive been trying the query:
    $query = "SELECT product_name FROM products WHERE {$_POST['barcode']} LIKE 'product_id%'";
    Can anyone see the error? As im getting nothing returned.

    Any help would be great!

    cheers

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use substr function

    $codeno = substr($_POST['barcode'], 0, 1);

    return the digits of a string between the positions 0 and 1
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2005
    Location
    Venlo, the Netherlands
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use SUBSTRING in sql too


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •