我需要下面的帮助,我知道它过去曾提出过,但我目前正在努力找出错误不能使用 stdClass 类型的对象作为在线数组
$score[$counter] = ($bronze * $tempArray[6]) + ($silver * $tempArray[5]) + ($silver * $tempArray[4]);
代码:
<?php
//turning the date other way around that is why explode the date string and stored in an Array
$gold=$_GET['gold_input'];
$silver=$_GET['silver_input'];
$bronze=$_GET['bronze_input'];
$gdp_value=$_GET['gdp_checked'];
$link = new mysqli('localhost', 'root', '','coa123cdb');
$myArray = array();
//data format for information
//[{"name":"Ahmet Akdilek","country_name":"Turkey","gdp":"773091000000","population":"72752000"}
$query = "SELECT * FROM coa123cdb.Country";
$result = mysqli_query($link, $query)
or die("Error: ".mysqli_error($link));
$row_cnt = $result->num_rows;
if ($result = $link->query($query)) {
$tempArray = array();
$scorex=array($row_cnt);
$score=(object)$scorex;
$counter=0 ;
//while($row = $result->fetch_object()) {
while($row=mysqli_fetch_object($result)){
$tempArray = $row;
if($gdp_value==0)
{
$score[$counter]=($bronze*$tempArray[6])+($silver*$tempArray[5])+($silver*$tempArray[4]);
}
else
{$score[$counter]=($bronze*$tempArray[6]+$silver*$tempArray[5]+$silver*$tempArray[4])*$tempArray[1]/$tempArray[2]/10000;
}
array_push($tempArray, $score[$counter]);
array_push($myArray, $tempArray);
$counter=$counter+1;
}
//var_dump($score);
echo json_encode($myArray);
}
$result->close();
$link->close();
?>