0

好的,所以我正在尝试写一些分析美国总统候选人的东西。

我正在尝试在给定的一天添加所有值 - 我是其中的一部分。

无论如何,$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"];
}
4

0 回答 0