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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:26:13+00:00 2026-05-23T11:26:13+00:00

I am creating SQL query based on user input: // user input $amount =

  • 0

I am creating SQL query based on user input:

// user input
$amount = '20';

// query in zend 
$select->where('amount = ?', $amount );

Now according to new requirements user can input in following formats as well:

$amount = '20';
$amount = '<20';
$amount = '<=20';
$amount = '>20';
$amount = '>=20';
$amount = '=20';

I think you understand the new feature. So how can I parse $amount variable to fit it in above query? I have to separate number and sign from $amount variable to use them on their proper position. And if there is wrong sign(i.e $amount='$%20'; ) then it should consider it as equal sign(i.e $amount='=20'; )

What approach should I follow to solve this?

Thanks

  • 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-05-23T11:26:14+00:00Added an answer on May 23, 2026 at 11:26 am
    $parts = array();
    if (preg_match('/^(\D+)?(\d+)$/', $amount, $parts)) {
        $operator = (!in_array($parts[1], array('=', '<', '<=', '>=', '>'))) ? '=' : $parts[1];
        $value    = $parts[2];
        $select->where('amount ' . $operator . ' ?', $value );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a SQL query string in android code which goes as follow: SELECT
I have a SQL query I'm having trouble creating using NHibernate Criteria: SELECT ID,
i am dynamically creating sql query for inserting multiple records in one hit.Suppose no
I'm working on creating a SQL query that will pull records from a table
I have an Sql query that looks up a person based on SSN and
I need an example of creating t-sql query to load next 10 records (depends
I'm creating a report (in Crystal Reports XI) based on a SQL stored procedure
I need help creating an SQL query to count rows broken out on two
I need help with improving the performance of the following SQL query. The database
I'm having issues creating a valid sql query. Im trying to check if 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.