Just started to learn php question may not sound quite correct for the more experienced.

I need to fetch rows by date from a database table and output the row data into a particular div container on the page.

id | name | last_name | Date (date format 2019-01-20, standard no change)

Here such a line in a DB.

I need all the lines up to the date (today) to be in div class = "box", if today's date is entered in the string, then the line goes to the markup div class = "box2".

view in mark is such.

<div class="box"> <div>Строка с сегодняшней датой</div> <div>Строка с сегодняшней датой</div> </div> <div class="box2"> <div>Строка не достигшая сегодняшней даты</div> <div>Строка не достигшая сегодняшней даты</div> <div>Строка не достигшая сегодняшней даты</div> </div> function get_table(){ global $link; $sql = "SELECT * FROM `all_name` ORDER BY `priority`,`date`"; $result = mysqli_query($link, $sql); $server = mysqli_fetch_all($result, MYSQLI_ASSOC); return $name_list; } 

With this method, I pull data from the database, it builds on the priority and date of the string, in one.

 `<?php foreach($$name_list as $list_part): <span class="icon"><?=$list_part['name']?></span> <span class="icon"><?=$list_part['last_name']?></span> <span class="icon"><?=$list_part['date']?></span> <?php endforeach;?>` 

I use this method to insert a document into a div in html. I tried to write the function directly and then output it in one line.
. I do not know how to write a function that will check the list for a date and, based on the date, output it where I need it. Experience in php week, especially do not be angry.

    1 answer 1

    You can add a calculated column by which to set the class to the element of the row.

      $sql = "SELECT *, ( date >= CURRENT_DATE()) as futu FROM `all_name` ORDER BY `priority`,`date`"; 

    Although if you do in the form indicated in your example, those are in a separate block, then in this query you need to add the directive group by futu

    I am writing from the phone, then I'll fix it.

    • Essentially $ sql = "SELECT * FROM all_name ORDER BY priority , date "; It serves me to sort my lists by date and given priority. But how to scatter already ordered lines into a completely different container div, I have no idea. Just tried to provide all the data that I have, so that people would be easier to advise what to do. - frel freloich pm