Jump to content

Search/Split/Compare


osyrys14

Recommended Posts

I'm trying to make a search where I pull information out of the column that is date/time (2013-03-29 14:00:00) and have a form search the information by a range provided.  I was helped in another thread and I was incorrect in the procedure I need to do, but this is the code I'm using to select * from the db, but what I need to do is display just the ones between the date chosen on the form that submits the query.  Any and all help is greatly appreciated!

 

$mydate1 = sprintf('%4d-%02d-%02d', 
    intval($_GET['year']), intval($_GET['month']), intval($_GET['day']));
$mydate2 = sprintf('%4d-%02d-%02d', 
    intval($_GET['year2']), intval($_GET['month2']), intval($_GET['day2']));

$sql = "SELECT *
        FROM $db_tb_name
        WHERE `$db_tb_atr_name` LIKE '%$query%'
        AND `6` > '$mydate1' AND  `6` < '$mydate2'";

 

 

Link to comment
https://forums.phpfreaks.com/topic/276280-searchsplitcompare/
Share on other sites

It's a dummy database to get the information functional and I have not gotten header names from the client yet so right now, they are all 1, 2, 3, 4, 5, 6, 7, 8, etc.  :)  

 

That gets me the correct query string, but since the query is set to just a date format, and the table is date/time, I'm still getting no results.  Is there a way to split at the space between the date and time and search that way?  The format in the db is 2013-03-29 14:00:00 and the form/search is only 2013-03-29.

 

Thanks so much for the help!

Link to comment
https://forums.phpfreaks.com/topic/276280-searchsplitcompare/#findComment-1421747
Share on other sites

Then convert them to timestamps. MySQL has a ton of date/time functions. Just go read up on them to see what one meets your needs.

 

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestamp

 

 

$sql = "SELECT *
        FROM $db_tb_name
        WHERE `$db_tb_atr_name` LIKE '%$query%'
        AND `6` BETWEEN TIMESTAMP('$mydate1')
                    AND TIMESTAMP('$mydate2')";
Link to comment
https://forums.phpfreaks.com/topic/276280-searchsplitcompare/#findComment-1421750
Share on other sites

I put something in the text box on the search, now it gets this

 

 

  1. SELECT * FROM cdr WHERE `8` LIKE '%EFM%' AND `6` BETWEEN TIMESTAMP('2012-09-02') AND TIMESTAMP('2012-09-03')

It's searching 2 fields, first one (8) is an ID code, the other we've been working on is a time/date stamp.  Is it possible to make them work together?

Link to comment
https://forums.phpfreaks.com/topic/276280-searchsplitcompare/#findComment-1421753
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.