A
A
Aigul_per2016-02-26 12:27:11
PHP
Aigul_per, 2016-02-26 12:27:11

How to retrieve data from database (PHP)?

Help, please) there is a table `p_operativ`. I enter the date there in the form: they $date = (date("Y.m.d"));
are entered into the database in the form of 2015-12-08 type date. Further I want to display the request the data relating to a certain date. I define the date like this:

$v = date ("Y-m-d", time() - ( -1 + date("N")-1) * 24*60*60);

(we need dates in the current week. this is Tuesday) and the query itself to the database
$hz_query = "select * from `p_operativ`
    where `po_agent` = ".$id_row['p_user_id']." and `po_date` = ".$v;
    $hz_res = mysql_query($hz_query) or die(mysql_error());
    $d = mysql_num_rows($hz_res);
    $hz_row = mysql_fetch_assoc($hz_res);

var_damp outputs: string(81) "select * from `p_operativ` where `po_agent` = 188 and `po_date` = 2016-02-25"
but no data is output. mysql_num_rows says 0. how to display correctly?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
IIISpikerIII, 2016-02-27
@Aigul_per

And it's not about the quotation marks around the date?

A
Andrey, 2016-02-26
@VladimirAndreev

see which of the conditions returns 0 rows..

A
Aigul_per, 2016-02-26
@Aigul_per

the one associated with the date. if you remove and `po_date` = ".$v then the data is displayed

I
Igor, 2016-02-26
@unitby

1. where you make a date, use mktime
2. if you need days from today (for example, 7 days from today), then filter at the mysql level,
see dev.mysql.com/doc/refman/5.7/en/date-and-time-func ...
interval bugs you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question