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 8538549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:08:36+00:00 2026-06-11T11:08:36+00:00

I have some sql that searches a db table for a number from a

  • 0

I have some sql that searches a db table for a number from a form input.

An good example would be the following rows:

124
1240
12400
124000

My sql is a simple like statement:

SELECT NUMBER FROM TABLE WHERE NUMBER LIKE '$number%'

If the use searched for 124, I would get find 4 rows which is fine.

My question is, if the user typed in 12400000, how can I return the row with 124000?
I’m assuming that I would need to loop back through the number until a row is found?

My input requires a min of 3 numbers before the sql is run, so I would want to stop the loop at 3 numbers.

With php and or SQL, is there a method that allows me to count back on a string to a defined point; string back to the 3rd Character?

  • 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-11T11:08:37+00:00Added an answer on June 11, 2026 at 11:08 am

    Just make an array from that input and use the IN:

    $_POST['number'] = '124000';
    
    $number = (string)(int)$_POST['number'];
    
    $numbers = array();
    $inNumber = '';
    if(strlen($number) > 2){
        $baseNumber = substr($number, 0, 3);
        $numbers[] = $baseNumber;
        for($i=3; $i<=strlen($number)-1; $i++){
            $inNumber.= $number[$i];
            $numbers[] = $baseNumber.$inNumber;
        }
    
        $tosearch = implode("','", array_reverse($numbers));
        $query = "SELECT * FROM `TABLE` WHERE `NUMBER` IN ('".$tosearch."') ORDER BY FIELD(`id`, '".$tosearch."')";
        echo $query; // SELECT * FROM `TABLE` WHERE `NUMBER` IN ('124000','12400','1240','124') ORDER BY FIELD(`NUMBER`, '124000','12400','1240','124')
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some script that is delivering a series of rows from an SQL
I have some Crystal Reports connecting to a Sql Server db that I would
I have C# application that must store some information into MS SQL that would
I'm having some trouble with an SQL statement that have to find the number
I have a form that is trying to insert some data into an SQL
I have some sql statements that calculates some numbers. It's possible (with bonus points/penalty
I have some code that uses the SQL Server 2005 SMO objects to backup
Hi I have some software written in VB6.0 that uses an SQL Server, but
I am doing some performance testing and have found that SQL seems to be
I have a Microsoft SQL server DB that imports some data which needs a

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.