English 中文(简体)
php 代码t 进入 lo(Msqli)
原标题:php code doesn t enter loop (mysqli)
  • 时间:2012-05-19 00:09:35
  •  标签:
  • php
  • mysqli

I try to make a diagram with RGraph(JS). I have a user counter on my site. And now I want to make a user-statistic with this diagram.

然而,我编制了一个清单,用于每一点(形成一个选择月和年的形式)。

我的问题是,《法典》将创造新的价值观(日子和大夫)的 lo。

任何想法?

该守则:

$days = 0;
$day_value = array();

//check months which have 30 days
if (in_array($month, array(4,6,9,11))) {
    $days = 30; 

}
//leapyear?
if ($month == 2) {
    if ($year%4 == 0) {
        $days = 29;
    } else {
        $days = 28;
    }
} 

//Count users for each day
for ($i=1; $i<=$days; $i++) {
    $sql = "SELECT
                 Anzahl
            FROM
                 Counter
            WHERE
                 YEAR(Datum) =  ".$year."  AND
                 MONTH(Datum) =  ".$month."  AND
                 DAYOFMONTH(Datum) =  ".$i." ";
    if (!$result = $db->query($sql)) {
        return $db->error;
    }

    $row = $result->fetch_assoc();
    $day_value[$i] = (int)$row[ Anzahl ];
} 

//delete list for new month/year
$sql = "DELETE
        FROM
            Statistics
           ";
if (!$result = $db->query($sql)) {
    return $db->error;
}

//Create list with values for each day
for ($j=1; $j<=$days; $j++) {
    $sql = "INSERT INTO 
                Statistics(Day,Count)
            VALUES 
                (?, ?)";
    $stmt = $db->prepare($sql);
    if (!$stmt) {
        return $db->error;
    }
    $stmt->bind_param( ii , $j, $day_value[$j]);
    if (!$stmt->execute()) {
        return $stmt->error;
    }

    $stmt->close();
}
最佳回答

$days is set to 0, it only changes if $months is 2,4,6,9,11 so for every other value of $month $days will be 0 and not enter the for loop.

if (in_array($month, array(4,6,9,11))) {
//code
}
elseif ($month == 2) {
//code
}
else{
//code
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签