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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:00:45+00:00 2026-05-31T11:00:45+00:00

I am querying a large number of codes from my database, and need to

  • 0

I am querying a large number of codes from my database, and need to have some validation before a user can input another code in to the database.

An example code would be this:

TD-BR-010212-xxxxxxxx

Where TD represents a promotion, BR represents a place, the numbers represent a date, and the rest are random.

My problem is that before the code is entered into the DB, I want to check to see if the date and place for that code already exists, as they should not be allwed to enter a code from the same place and date.

I assume it would be something within a loop as I already have:

$location_part_of_td = $code[2].$code[3];
$date_part_of_td = $code[4].$code[5].$code[6].$code[7].$code[8].$code[9];

$trade_day_result = mysql_query('SELECT * from wp_scloyalty WHERE promotion_type = trade-day') or die(mysql_error());  // Pulls all trade day codes from the database and checks the date part of the code. 

// the date part exists with the same area part, user cant redeem.
while($info = mysql_fetch_array( $trade_day_result )) 
{ 

     $code = $info["product"];

} 

But Im just not sure about the best way to check the strings..

  • 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-31T11:00:46+00:00Added an answer on May 31, 2026 at 11:00 am

    You can use a MySQL LIKE clause to get entries in your DB that resemble your code.

    Example:

    $code_exists = mysql_query( 
          "SELECT 'a' FROM table_name WHERE column_name LIKE 'TD-BR-010212-%'"
    );
    if(mysql_num_rows($code_exists) > 0) {
        // The specified place/date is taken
    } else {
        // No promotion at place BR on the specified date.
    }
    

    The ‘%’ is used as a wildcard in SQL LIKE clauses.

    • 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 that contains a large number of polygons, one for
i'm querying a database like this: SELECT * from Log WHERE cookieId IN (select
I'm querying a very large activity log in a MySQL database, trying to figure
I have a fairly large SQL Server database; I'd like to pull 4 tables
I have a rather large DBF file, about 40 megs, that I need to
This is more a conceptual question. It's inspired from using some extremely large table
I have a Java project which will include a number of large SQL statements
I have a MySQL(innodb) table 'items' with the following characteristics Large number of rows,
I have just found RowSets for database querying with JDBC. They are stateless and
I have a large number of records (10,000, increasing every day) that essentially is

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.