V
V
Viktor Taran2020-09-08 13:18:07
PHP
Viktor Taran, 2020-09-08 13:18:07

How to limit UPDATE input to current date only?

We write the generated number to the table.
5f575cb26e94b817362212.png
Actually, everything is fine, only I need to write only the current date and not generate all the previous ones, I need to fill them with correct numbers.
I show the whole file because it is small.

<?php


require 'connect.php';

$total = 1600000;
   
$random = array(
  'workweek' => array(-4,7),
  'holiday' => array(-16,-4)
);

$q = mysql_query("SELECT * FROM `betaintranet`.`ad_stat_cleaned`");
while($row = mysql_fetch_assoc($q))
{
  $now = time();
  $daysInMonth = date('t', $now);
  $dayOfWeek = date('w', mktime(0,0,0, date('m', $now),date('d', $now), date('y', $now)));
  $isHoliday = $dayOfWeek == 6 || $dayOfWeek == 0;
  $rand = $isHoliday ? $random['holiday'] : $random['workweek'];
  $rand = rand($rand[0],$rand[1]);
  $daily = $total / $daysInMonth;
  $part = round($total / $daysInMonth / 100 * $rand);
  $modification = round($row['modification'] + ($daily + $part) / 24);
  $sql = "UPDATE `betaintranet`.`ad_stat_cleaned` SET `betaintranet`.`ad_stat_cleaned`.`modification` = '{$modification}' WHERE 
          `betaintranet`.`ad_stat_cleaned`.`bid` = '{$row['bid']}' AND 
          `betaintranet`.`ad_stat_cleaned`.`date` = '{$row['date']}'";
  mysql_query($sql) or die(mysql_error());
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Spartak (Web-StyleStudio), 2020-09-08
@shambler81

$q = mysql_query("SELECT * FROM `betaintranet`.`ad_stat_cleaned` WHERE `date`='".date("Y-m-d")."'");
while($row = mysql_fetch_assoc($q))
{
... 
}

Victor Taran ,
UPDATE to copy the whole show into modification

For current date
mysql_query("UPDATE `betaintranet`.`ad_stat_cleaned` SET `modification`=`show` WHERE `date`='".date("Y-m-d")."'") or die(mysql_error());

For all records in the table
mysql_query("UPDATE `betaintranet`.`ad_stat_cleaned` SET `modification`=`show`") or die(mysql_error());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question