0

私はPHPが初めてなので、これまでのところ、この場所は私にとって大きな助けになっています! とにかく、私はこのコードを持っています

$month = "
SELECT SUM(`duration`) 
FROM `connlist` AS `month_sum` 
WHERE `vatsimid` = '$vatsimid' 
AND MONTH(atc_online) = " . $pmonth . "  
AND YEAR(atc_online) = " . $year . "
"; 

$month をエコーアウトすると、それが得られます

SELECT SUM(`duration`) 
FROM `connlist` AS `month_sum`
WHERE `vatsimid` = '1070757' 
AND MONTH(atc_online) = 07 
AND YEAR(atc_online) = 13

これを phpMyAdmin で直接使用すると、魅力的に機能しますが、php Web ページから使用しようとすると、構文エラーが発生します。私はphp 5.4を使用しています

ありがとう!

編集:完全なコード:

<?php
//open MySQL connection
$mysql = mysqli_connect('host', 'un', 'pass', 'table') 
or die ( "MySQL Error: ".mysqli_error() );

//Get and decode residents data
$jsonData = file_get_contents("link");
$phpArray = json_decode($jsonData, true);

//Start Operations
foreach ($phpArray as $key => $value) {

//Get controller hours for today
$vatsimid = $value[vatsimid];

//Get previous month
$pmonth = date("m", strtotime("-35 days") ) ;
$pmonthName = date("M", strtotime("-35 days") ) ;
echo $pmonth;
echo $pmonthName;


//This year or last year? 
If (date("M") != "Jan") { //Checks that it's not January of the next year.
    $year = date("y");
}
else {
    $year = date("y", strtotime("-1 month") );
}

echo $year;

//Search and sum entries during last month
$month = "SELECT SUM(`duration`) 
FROM `connlist` AS `month_sum` 
WHERE `vatsimid` = '$vatsimid' 
AND MONTH(atc_online) = " . $pmonth . " 
AND YEAR(atc_online) = " . $year . "";
echo $month;
echo "</br> </br>";

$result = mysqli_query($mysql,$month);
$row = mysqli_fetch_assoc($result); 

$month_sum = $row['month_sum'];
echo $month_sum;

//Updates data in atclist 

$datainsert = "
UPDATE `atclist`
SET " . $monthName . "=" . $month_sum . "
WHERE vatsimid = " . $vatsimid . "";
$insert = mysqli_query($mysql,$datainsert);

if (!$insert)
{
die('Error: ' . mysqli_error($mysql));
}  

}
/*
4

2 に答える 2

3

もしかして:

SELECT SUM(duration) AS month_sum 
FROM connlist 
WHERE vatsimid = '1070757' AND MONTH(atc_online) = 07 AND YEAR(atc_online) = 13
于 2013-08-10T02:37:06.700 に答える