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

  • SEARCH
  • Home
  • 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 6006319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:31:19+00:00 2026-05-23T01:31:19+00:00

I have the following in database field id = id, Xterminal = 1234, Testdata

  • 0

I have the following in database field

id = id,
Xterminal = 1234,
Testdata = 1234',
date BETWEEN $Date1 AND  $Date2,
MyVar = $myVar;

I want to use it in my sql statement. I have $Date1 = ‘2011-01-09’ and $Date2 = ‘2011-03-09’ set in my scripte above the sql statement.
I have $myvar setup to $myVar = 3. But it doesnt convert the variables in sql and when I do print_r on $sql it shows the variables and even in query it shows variables not the values of them

I doing the following

$conditions = explode(',',$results['conditions']);   

print_r($condidtions) gives

Array
(
[0] =>
id = id
[1] =>
Xterminal = 1234
[2] =>
Testdata = 1234
[3] =>
date BETWEEN $Date1 AND $Date2
[3] =>
MyVar = $myVar;

)

$sql1 = "Select * from table where ";
$sql2 = implode(' AND ',$conditions);

$sql = $Sql1.' '.$sql2;

print_r(“$sql”) gives

SELECT
*
FROM

table
WHERE
id = id AND
Xterminal = 1234 AND
Testdata = 1234 AND
date BETWEEN $Date1 AND $Date2 AND
MyVar = $myVar;

Not sure why is it not taking my variable values that I have defined alreadt at the to of script

  • 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-23T01:31:20+00:00Added an answer on May 23, 2026 at 1:31 am

    It sounds like what you’re saying is that the string date BETWEEN $Date1 AND $Date2, came from the database. If that is the case, then your variables are not being evaluated, because this is just data…

    You can use eval(), but this is a dangerous path if users could possibly create these conditions.

    $conditions = explode(',',$results['conditions']);
    for ($x = 0; $x < count($conditions); $x++) {
        eval("\$conditions[\$x] = \"" . $conditions[$x] . "\";");
    }
    print_r($conditions);
    

    Edit: I put together a working PHP sample for this, visible at http://gfosco.kodingen.com/conditions.php and here is the source:

    <?php
    
    $conditions = array("date BETWEEN '\$Date1' AND '\$Date2',");
    
    echo "\$conditions before the loop: <BR>";
    var_dump($conditions);
    
    $Date1 = '1/1/2011';
    $Date2 = '12/31/2011';
    
    echo "<BR>\$Date1 = " . $Date1 . "<BR>";
    echo "\$Date2 = " . $Date2 . "<BR>";
    
    for ($x = 0; $x < count($conditions); $x++) {
        eval("\$conditions[\$x] = \"" . $conditions[$x] . "\";");
    }
    
    echo "<BR>\$conditions after the loop:<BR>";
    var_dump($conditions);
    

    This outputs:

    $conditions before the loop: 
    array(1) { [0]=> string(35) "date BETWEEN '$Date1' AND '$Date2'," } 
    $Date1 = 1/1/2011
    $Date2 = 12/31/2011
    
    $conditions after the loop:
    array(1) { [0]=> string(41) "date BETWEEN '1/1/2011' AND '12/31/2011'," }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following text in SQLITE database in TEXT field The exact date of
In my mysql database I have the following information in a page name field.
I have a database with the following table: PATIENT (PATIENT_ID*, MEDICAL_EXAMINATIONS) where the field
I have some info saved in a database field with the following structure: First
I have the following schema: Database: test. Table: per_login_user, Field: username (PK), password Database:
I have form with checkboxes loaded from database (I use entity field type). Checkboxes
I have the following database schema (Microsoft SQL Server Compact Edition): How can I
I have a SQL database with has the following: Customer, Item, Clothing and Food.
I have the following database person_id| field a | field b |friend_id Lets suppose
I'm working with C# .Net and ms-access database. I have the following SQL query:

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.