0

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

3
Contributors
5
Replies
15
Views
1 Year
Discussion Span
Last Post by rubberman
0

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

0

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...

0

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;
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.