Hi - I am very new to this.
I have a joomla site where I am trying to get a date from a datepicker and display parts of my table using the date. Two major problems:
Datepicker - for future.
$dateSelected1 = $dateSelected . " 00:00:01";
$dateSelected2 = $dateSelected . " 23:59:58";
echo 'x' .$dateSelected1 .'x';
echo "<br>";
echo $dateSelected2;
echo "<br>";
$db_host = "localhost";
$db_database = "whatsonthatday";
$db_username = "digitach";
$db_password = "";
$dbcnx = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_database);
//$query = "SELECT * FROM 'whatson' where fldDate between '$dateSelected1' and '$dateSelected2' ";
$query = "SELECT * FROM whatson where fldDate between '2016-06-21 00:00:00' and '2016-06-21 23:59:59'";
//$query = "SELECT * FROM whatson";
echo $query;
echo "<br>";
$q = mysql_query($query);
echo $q;
This works as expected:
DateSelect:
2016/06/21
x2016/06/21 00:00:01x
2016/06/21 23:59:58
SELECT * FROM whatson where fldDate between '2016-06-21 00:00:00' and '2016-06-21 23:59:59'
Resource id #244
Total number in the database is 4
2016-06-21 18:00:002016/06/212016-06-21 18:00:002016/06/212016-06-21 21:00:002016/06/212016-06-21 21:00:002016/06/21
But, of course, I don't want this.
When I comment out the $query = "SELECT * ........... line
And uncomment the line above I get:
DateSelect:
2016/06/21
x2016/06/21 00:00:01x
2016/06/21 23:59:58
SELECT * FROM 'whatson' where fldDate between '2016/06/21 00:00:01' and '2016/06/21 23:59:58'

Total number in the database is
Which means the query is the same but does not find the records.

Any help please??

Dave

Just noticed the single quotes around whatson in the line I needed.
Deleted them and it all works.
Sorry!
Will work on the datepicker problem and report back.

Dave

So, why are you using mysql arguments (deprecated) instead of mysqli? Also, your argument to mysql_select() is incorrect. I think you should be using $dbcnx instead of $db_database. $db_database is only a name, not a database connection. Also, you are not capturing any database errors that mysql is generating as far as I can see.

So, go back to the documentation on php.net for more study...

Member Avatar for diafol

Please use </> Code button on the editor if you insert code.

$dateSelected1 = $dateSelected . " 00:00:01";
$dateSelected2 = $dateSelected . " 23:59:58";
echo 'x' .$dateSelected1 .'x';
echo "<br>";
echo $dateSelected2;
echo "<br>";
$db_host = "localhost";
$db_database = "whatsonthatday";
$db_username = "digitach";
$db_password = "";
$dbcnx = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_database);
//$query = "SELECT * FROM 'whatson' where fldDate between '$dateSelected1' and '$dateSelected2' ";
$query = "SELECT * FROM whatson where fldDate between '2016-06-21 00:00:00' and '2016-06-21 23:59:59'";
//$query = "SELECT * FROM whatson";
echo $query;
echo "<br>";
$q = mysql_query($query);
echo $q;

Thanks chaps.
I am using 'The web book" as my primary reference which is slightly out of date. I lifted the mysql code from that as is.
For the last week my head has been swimming, what with JS, php, cms, etc.
Getting closer though.

Dave

Just remember that the mysql... code in PHP has been deprecated in favor of mysqli... Eventually, the older stuff will not be supported, and possibly not available.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.