I have a range of dates that is checking if the dates entered by a user coincide with some day of offer in the database, to coincide, print the new price, but it gives me two problems: 1) If I have more than two offers in the DB, it prints twice the prices and dates 2) if an offer is from 06-04-2018 until 08-04-2018 it gives me the new price, but it is returned to me on 06-05-2018 until 06-05-2018
date range code:
$price = Data::PriceSearch("price_hdcd");
for($i=$dateinstr; $i<=$dateoutstr; $i = date("Y-m-d", strtotime($i ."+ 1 days"))){
$UNIX = strtotime($i);
$STR = date("d-m-Y", $UNIX);
foreach ($price as $row => $priceout) {
if ($STR >= $priceout['dateini'] && $STR <= $priceout['datefin'] ) {
echo '
<tr>
<th scope="row">'.$STR.'</td>
<td>'.$priceout['cd'].' €</td>
<td>'.$priceout['mp'].' €</td>
<tr>';
} else {
$totalcd = $PriceSystemArray['cd'];
$totalmp = $PriceSystemArray['mp'];
echo '
<tr>
<th scope="row">'.$STR.'</td>
<td>'.$totalcd.' €</td>
<td>'.$totalmp.' €</td>
<tr>';
}
}
}
}
}
db code:
public function PriceSearch($table){
$stmt = Connection::Connect()->prepare("SELECT * FROM $table");
$stmt->execute();
return $stmt->fetchAll();
}