Question:

PHP/MySQL Select... Where... Question ?

by  |  earlier

0 LIKES UnLike

Is this a valid statement in PHP?

$result = mysql_query("SELECT * FROM events WHERE strtotime(event_stamp) BETWEEN $searchstart AND $searchend");

I assume that if you can use php functions in the middle of a query select statement it would store the whole table of output into my $result variable correct?

 Tags:

   Report

1 ANSWERS


  1. That would be correct.

    You might want to consider using a smalldatetime/datetime field for any time/date related fields...

    And be sure to add quotes:

    ... BETWEEN '$searchstart' AND '$searchend' ");

    EDIT:

    It shouldn't... but if all else fails:

    BETWEEN '" . $searchstart . "' AND '" . $searchend . "' ");

    ... is another way to do it.

    It all depends on what type of field the event_stamp is - I assume a datetime filed, or a timestamp... I have to admit I'm more used to T-SQL and MS SQL, and these types of fields require comparisons using quotes around the values.

    The resulting SQL string is what matters. If the actual PHP string is enclosed in double quotes, single quotes are just plain characters that shouldn't change the variable assignment.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.