php - Data taken from mysql display division if the date by day is changed -
currently have code takes data mysql , displays text , tried make underline bar if date day changed, no luck
the first picture shows code , second 1 i'm trying do. tried check if current date different new 1 no luck.
how detect date change current code, can make break between same day easy viewing?
<?php chdir(__dir__); error_reporting(e_strict | e_all); ini_set('display_errors', true); ini_set('display_startup_errors', true); require_once 'config.php'; $mysqli = new mysqli($server, $db_user, $db_password, $database); if ($mysqli->connect_error) { die("connection failed: " . $conn->connect_error); } $sql_list = "select date, name, quantity, 0 price, 'download' source downloads union select date, name, quantity, price, 'sale' source sales order by(`date`) desc"; $result_list = $mysqli->query($sql_list); $ans_lists = array(); while($row = $result_list->fetch_assoc()){ $source =$row["source"]; $name = $row["name"]; if (stripos($source, "sale") !== false) { $price = $row["price"] ."$"; }else{ $price = ""; } $date_str = strtotime($row["date"]); $year = date('y', $date_str); $month = date('m', $date_str); $day = date('d', $date_str); $hour = date('h', $date_str); $minute = date('i', $date_str); $ans_list = "" . sprintf('%s-%s-%s %s:%s',$year,$month,$day,$hour,$minute) . ", " . $name . " - " . $source . " added " . $price . ""; //echo $ans_list; $ans_lists[] = $ans_list; } $count = 0; $max_lines = 1000; foreach($ans_lists $f){ if ($count >= $max_lines){ break; } if (stripos($f, "sale") !== false) { $class = "sales"; $text = "text-sales"; if (preg_match("/(crcv2)/i", $f)) { $squaresales = "crcv2-sales"; }else if(preg_match("/(crc12)/i", $f)){ $squaresales = "crc12-sales"; } } else{ $class = "row"; $square = "general"; $text = "text-general"; $squaresales = ""; } if (preg_match("/(crcv2|crcpv2-01|crcpv2-02|crcpv2-03|crcpv2-04|crcpv2-05|crcpv2-06|crcpv2-07|crcpv2-08|crcpv2-09|crcpv2-10|crcpv2-11|crcpv2-12)/i", $f)) { $square = "crcv2"; }else if(preg_match("/(crc12|crcp01|crcp02|crcp03|crcp04|crcp05|crcp06|crcp07|crcp08|crcp09|crcp10|crcp11|crcp12|crcp13|crcp14)/i", $f)){ $square = "crc12"; } $count++; echo "<div class='".$class." scale'><a class='".$square."'></a><a class='".$squaresales."'></a><a class='".$text."'>".$f."</a></div>\r\n"; } $mysqli->close();
try changing $ans_lists[] = $ans_list
this:
// here youll 20150708 $ymd_date = date( 'ymd', strtotime($row["date"]) ); // prepare array results day if ( !isset( $ans_lists[$ymd_date] ) ) { $ans_lists[$ymd_date] = array(); } // add result specific date $ans_lists[$ymd_date][] = $ans_list;
and change foreach($ans_lists $f){
iterator to
foreach($ans_lists $ymd_date => $array_of_entries){ foreach($array_of_entries $f){ // ... here stays printing logic // ... } // here ends 1 specific day // can output breakline here or echo '<hr>'; }
Comments
Post a Comment