好的,所以我正在尝试写一些能够分析美国总统候选人的东西。
我正试图在某一天添加所有值 - 我是通过它的一部分。
无论如何,$ romlinearray - 我想在里面有两个值,日期和给定日期的值。我想将它们插入if ($romneydiff == 0) {
块中。
我遇到的问题是生成一个带有键名的数组(即我希望能够执行$ romlinearray [“value”])并让它拉一个值,但该值不会插入到以后。
如何使用键创建数组,但是还没有值?
$resultromney = mysql_query("SELECT category, value, timestamp from results where name='".$chartname2."'");
if (!$resultromney) {
die('Invalid query, please contact administrator');
}
$posromney = 0;
$negromney = 0;
$dateromney = "1/1/2012";
$romray = array();
while ($twitromney = mysql_fetch_assoc($resultromney))
{
$romneytime = intval($twitromney["timestamp"]);
$romneydate = date('m/d/Y', $romneytime);
$romlinearray = array(); // THIS IS WHERE THE PROBLEM IS
$romneydiff = date_diff($dateromney, $romneytime);
$PLromney = 0;
$NLromney = 0;
$totalromney = 0;
if ($romneydiff == 0) {
switch ($twitromney["category"]) {
case "composed":
$PLromney = $PLromney + $twitromney["value"];
break;
case "elated":
$PLromney = $PLromney + $twitromney["value"];
break;
case "clearheaded":
$PLromney = $PLromney + $twitromney["value"];
break;
case "agreeable":
$PLromney = $PLromney + $twitromney["value"];
break;
case "energetic":
$PLromney = $PLromney + $twitromney["value"];
break;
case "unsure":
$NLromney = $NLromney + $twitromney["value"];
break;
case "tired":
$NLromney = $NLromney + $twitromney["value"];
break;
case "depressed":
$NLromney = $NLromney + $twitromney["value"];
break;
case "guilty":
$NLromney = $NLromney + $twitromney["value"];
break;
case "confused":
$NLromney = $NLromney + $twitromney["value"];
break;
case "anxious":
$NLromney = $NLromney + $twitromney["value"];
break;
case "hostile":
$NLromney = $NLromney + $twitromney["value"];
break;
case "confident":
$PLromney = $PLromney + $twitromney["value"];
break;
}
$totalromney = $PLromney - $NLromney;
$romlinearray["value"] = $totalromney + $romlinearray["value"];
}