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 6578183

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:44:17+00:00 2026-05-25T15:44:17+00:00

I have a query: $startdate= date(‘Y-m-d H:i:s’,strtotime(-1 week)); $query = SELECT title FROM new_books

  • 0

I have a query:

$startdate= date('Y-m-d H:i:s',strtotime("-1 week"));

$query = "SELECT title FROM new_books ".
         "WHERE timestamp >= '$startdate' ";
$newbooks = mysql_query($query) or die (mysql_error());

Is the value of $startdate evaluated when $query is set, or when it’s called by mysql_query()?

For example say the above query returns 0 results (mysql_num_rows($newbook)==0) could I change $startdate and then call $newbooks = mysql_query... again, or would I need to set $query again first?

  • 0 0 Answers
  • 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-25T15:44:18+00:00Added an answer on May 25, 2026 at 3:44 pm

    The variable is evaluated at the time $query is set.

    It’s exactly like doing this:

    $query = "SELECT title FROM new_books ".
             "WHERE timestamp >= '" . $startdate . "' ";
    

    If you want to execute the same query multiple times with different parameters, use prepared statements:

    $query = $mysqli->prepare("SELECT title FROM new_books WHERE timestamp >= :startdate");
    
    $query->bind_params("s", $startdate);
    $query->execute();
    ...
    
    $query->bind_params("s", $an_other_startdate);
    $query->execute();
    ...
    

    See the examples at http://docs.php.net/manual/en/mysqli.prepare.php

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

Sidebar

Related Questions

I have a query on my database as such: SELECT * FROM expenses WHERE
I have this query return plannerDb.IndividualCalendars.Where(u => u.UserId == userId && u.StartDate.Date >= startDate
I have query like this SELECT AVAILABILITY_DATE_TIME FROM APPT_PROVIDER_AVAILABILITY WHERE AVAILABILITY_DATE_TIME between @START_DATE AND
I have a query like : SELECT .. FROM ... WHERE ... AND ISNULL(ICA.actual_appearance_date,
I have a MySQL query: SELECT COUNT(*) AS total, DATE_FORMAT(event.serverTime,'%Y-%m-%d') AS sdate FROM event
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted
I have a query that I'm executing from a .NET application to a SQL
I have written a MySQL query (Ad rotate algorithm) to fetch records from multiple
I have a query like this SELECT member_Id , PERIOD_DIFF( DATE_FORMAT(now(),'%Y%m'), DATE_FORMAT(memberToMship_StartDate,'%Y%m') ) +

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.