Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:09:48+00:00 2026-06-11T09:09:48+00:00

I have a database which contains the following : pnid partnumber desc code ====

  • 0

I have a database which contains the following :

pnid     partnumber       desc       code
====     ==========       ====       ====
1        123-12345        hdd        CMYK

So, the code field contains the pattern of the serial number I am looking for. What I would like to do is that I would like to fetch all the codes from my database, then check if a user input matches the code and display the part number of the matching code.

So saying that my input is ECMYK123456 then the function would return 123-12345.

I am really at lost. All I have is my basic PDO connection.

<?php
function checkPattern($inputString) {
    $dbuser = "root";
    $dbpass = "123456";
    $dbconn = new PDO('mysql:host=localhost;dbname=3parsfdb',$dbuser,$dbpass);  

    $dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbconn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $query = $dbconn->query("SELECT * FROM `partnumber` WHERE '%$inputString%' LIKE `ctcode`  LIMIT 1");
    foreach ($query as $row) {
        return $row['partnumber'];
    }
}

echo checkPattern("ECMYK12345");
?>

When I try the function, it returns nothing. What is wrong with the code?

Final Code :

<?php
function checkPattern($inputString) {
    $dbuser = "root";
    $dbpass = "123456";
    $dbconn = new PDO('mysql:host=localhost;dbname=3parsfdb',$dbuser,$dbpass);  

    $dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbconn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $query = $dbconn->query("SELECT * FROM `partnumber` WHERE '$inputString' like concat('%', ctcode, '%') LIMIT 1");
    foreach ($query as $row) {
        return $row['partnumber'];
    }
}

echo checkPattern("ECMYK12345");
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:09:49+00:00Added an answer on June 11, 2026 at 9:09 am

    Groan:

     SELECT *
     FROM partnumber
     WHERE "ECMYK123456" like concat('%', code, '%')
    

    Note that it can’t use an index on code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database called People which contains the following schema <id,name,foodchoice1,foodchoice2> .
I have a database table which contains an unsigned integer field to store the
I have MySQL database, where I store the following BLOB (which contains JSON object)
I have a database with a single table right now, which contains the following
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
Database: Sql Server I have table column named page_text which contains following value I
In a SQL server database, I have a table which contains a TEXT field
Please help me with following, I have a database which contain strings ( e.g.
I have a database which contains the link to audio files. I am trying
i have a database which contains an arabic tables , i can read it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.