Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的php循环没有用MYsql填充我的数据库_Php_Mysql_Loops_Increment - Fatal编程技术网

我的php循环没有用MYsql填充我的数据库

我的php循环没有用MYsql填充我的数据库,php,mysql,loops,increment,Php,Mysql,Loops,Increment,我有以下Mysql表和PHP代码 MySQL:我从存储表中选择存储量。它返回我的商店列表 我还有一张现金兑换表,上面有信息 PHP: 循环发生时,假定numberofdays是一个月中的天数 在while循环中,我执行一个sqlselect,它根据日期和存储从cashup表中返回我的值 在循环中,我增加我的天数,以允许在我所有的商店中循环31天,以返回现金支付总额值 //loop days $numberofdays = 31; $monthyear = NOV_2016; $x = 1;

我有以下Mysql表和PHP代码

MySQL:我从存储表中选择存储量。它返回我的商店列表

我还有一张现金兑换表,上面有信息

PHP: 循环发生时,假定numberofdays是一个月中的天数

在while循环中,我执行一个sqlselect,它根据日期和存储从cashup表中返回我的值

在循环中,我增加我的天数,以允许在我所有的商店中循环31天,以返回现金支付总额值

//loop days
$numberofdays = 31;
$monthyear = NOV_2016;
$x = 1;
        //loop days
        do {
            //string days info
            $thedate =  $x . '_' . $monthyear;

            if (strlen($thedate) == 10){
                    $thedate = '0' . $thedate;
                    }
                //Do select 
                mysql_select_db($database_localhost, $localhost);
                $query_showr = "select sum(cashup_cash) from cashiercashdata where cashup_date LIKE '$thedate' and cashup_store = '$store'";
                $showr = mysql_query($query_showr, $localhost) or die(mysql_error());
                while ($row_showr = mysql_fetch_assoc($showr))
                        {
                            //loop through record rows
                            foreach($row_showr as $row)
                                {
                                ///////$insertday = "recon_d" . $x . "_received";   
                                echo " Store : " .  $store . " Counter : " .  $x . ' : ' . gettype($x) . ' : ' . $row . ' : ' . gettype($row) . '<br>';
                            mysql_query("
                            update bankrecon
                            set recon_d10_received = '$row'
                            WHERE recon_store = '$store'
                            and recon_month = '$monthyear'
                            ");
                    }
                        }
$x++;
        } while ($x <= $numberofdays);
它在显示时正常工作,但不更新目标表。 有人能给我解释一下为什么numberofdays信息的循环不会触发列的更新,但是如果numberofdays是静态的,它会更新


现在,如果不知道目标表是什么样子,很难准确地知道,但我猜这与UPDATE语句有关

update bankrecon
    set recon_d10_received = '$row'
    WHERE recon_store = '$store'
    and recon_month = '$monthyear'
特别是此位:
set**recon\u d10\u received**='$row'


这是不是告诉表只在第10天更新?

两个示例表sql:

CREATE TABLE `bankrecon` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `recon_d10_received` varchar(45) DEFAULT NULL,
  `recon_store` varchar(45) DEFAULT NULL,
  `recon_month` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `data and store` (`recon_store`,`recon_month`,`recon_d10_received`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;


CREATE TABLE `cashiercashdata` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cashup_cash` int(11) DEFAULT NULL,
  `cashup_date` varchar(45) DEFAULT NULL,
  `cashup_store` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
session_start();

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$mysqli = new mysqli("localhost", "someuser", "somepass", "somedb");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

    $store = 'somestrome';
    $numberofdays = 31;
    $monthyear    = 'NOV_2016';
    $x            = 1;
    //loop days
    do {
        //string days info
        $thedate = $x.'_'.$monthyear;

        if (strlen($thedate) == 10) {
            $thedate = '0'.$thedate;
        }
        $showr = $mysqli->query("select sum(cashup_cash) as cashup_cash from cashiercashdata where cashup_date LIKE '$thedate' and cashup_store = '$store'")->fetch_assoc();
        if(!is_null($showr['cashup_cash'])){
            $sql = " INSERT INTO bankrecon (recon_d10_received,recon_store,recon_month) VALUES ('".$showr['cashup_cash']."','$store','$monthyear') ON DUPLICATE KEY UPDATE recon_d10_received='".$showr['cashup_cash']."'";
            $mysqli->query($sql);
            echo " Store : ".$store." Counter : ".$x.' : '.gettype($x).' : '.$showr['cashup_cash'].' : '.gettype($showr['cashup_cash']).'<br>';
        }


        $x++;
    } while ($x <= $numberofdays);
和php本身:

CREATE TABLE `bankrecon` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `recon_d10_received` varchar(45) DEFAULT NULL,
  `recon_store` varchar(45) DEFAULT NULL,
  `recon_month` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `data and store` (`recon_store`,`recon_month`,`recon_d10_received`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;


CREATE TABLE `cashiercashdata` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cashup_cash` int(11) DEFAULT NULL,
  `cashup_date` varchar(45) DEFAULT NULL,
  `cashup_store` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
session_start();

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$mysqli = new mysqli("localhost", "someuser", "somepass", "somedb");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

    $store = 'somestrome';
    $numberofdays = 31;
    $monthyear    = 'NOV_2016';
    $x            = 1;
    //loop days
    do {
        //string days info
        $thedate = $x.'_'.$monthyear;

        if (strlen($thedate) == 10) {
            $thedate = '0'.$thedate;
        }
        $showr = $mysqli->query("select sum(cashup_cash) as cashup_cash from cashiercashdata where cashup_date LIKE '$thedate' and cashup_store = '$store'")->fetch_assoc();
        if(!is_null($showr['cashup_cash'])){
            $sql = " INSERT INTO bankrecon (recon_d10_received,recon_store,recon_month) VALUES ('".$showr['cashup_cash']."','$store','$monthyear') ON DUPLICATE KEY UPDATE recon_d10_received='".$showr['cashup_cash']."'";
            $mysqli->query($sql);
            echo " Store : ".$store." Counter : ".$x.' : '.gettype($x).' : '.$showr['cashup_cash'].' : '.gettype($showr['cashup_cash']).'<br>';
        }


        $x++;
    } while ($x <= $numberofdays);

打印SQL查询,您将得到错误。不幸的是,打印SQL并回显值会得到相同的结果。信息与值正确呼应。意思是我的问题是正确的。内部循环中的更新正确地更新目标表,但仅当numberofdays变量设置为static 10 int时。由于某些原因而动态更改值的while循环或for循环的迭代会导致update语句没有正确响应当前我正在测试更新以重新确认收到的值。选择的目的是用每月每天的现金支付信息填充30家商店的网格。$x增量将在循环的每次迭代中动态更改。当numberofdays的静态整数为10时,更新工作正常。但是,当循环使用循环在where$x=10上迭代时,信息仍然正确回显,但更新忽略了目标表中norlan varchar列的值ti insert。请在服务器上查找表insert和文件,以便更清楚地理解。要插入的数据库称为cashup。