Jump to content

creating an array()


AV1611

Recommended Posts

Well, I guess you can't do this:
Any suggestions???

$graphValues$c[]=$row['RATING'];

[code]
while ($c <= $tl){
$EVAL=$NAME[$c];
$result2 = mysql_query("Select
Avg(surveyresults.RATING) as RATING, surveyresults.`DATE` From surveyresults
Where
surveyresults.EVALUATOR = '$EVAL'
AND DATE_SUB(NOW(),INTERVAL 30 DAY)<=DATE
Group By
surveyresults.`DATE`
Order By
surveyresults.`DATE` Asc");
while ($row = mysql_fetch_array($result2)){
         $graphValues$c[]=$row['RATING'];
}
[/code]
Link to comment
Share on other sites

Sorry,

What I am trying to do is crate a series of arrays, like this:
I am tryint to do $graphValues$c[]=$row['RATING']; to create the variable names dynamically...

$graphValues1[]
$graphValues2[]
$graphValues3[]

I am going to build a line graph with three different lines...

here is the error:

Parse error: parse error, unexpected T_VARIABLE in c:\inetpub\wwwroot\corp\graph30tl.php on line 65
Link to comment
Share on other sites

This seems to work...

[code]
<?php
$c=1;
$arrays = "graphValues" . $c;
$$arrays .=1;
$$arrays .=2;
$$arrays .=3;
$c=2;
$arrays = "graphValues" . $c;
$$arrays .=1;
$$arrays .=2;
$$arrays .=3;
$c=3;
$arrays = "graphValues" . $c;
$$arrays .=1;
$$arrays .=2;
$$arrays .=3;

echo $graphValues1[0];
echo "<br/>";
echo $graphValues1[1];
echo "<br/>";
echo $graphValues1[2];
echo "<br/>";
echo $graphValues2[0];
echo "<br/>";
echo $graphValues2[1];
echo "<br/>";
echo $graphValues2[2];
echo "<br/>";
echo $graphValues3[0];
echo "<br/>";
echo $graphValues3[1];
echo "<br/>";
echo $graphValues3[2];
echo "<br/>";

?>
[/code]

this gives:

1
2
3
1
2
3
1
2
3

//(here is the loop version)

<?php
for($c=1; $c<=3; $c++){
$arrays = "graphValues" . $c;
for($i=1; $i<=3; $i++){
$$arrays .=$i;
}
}
?>

Now, I just have to make it a loop...
Ken, I will study the multi-array... I've not done one before... but I get the concept...
I'm just starting to learn arrays the past couple of weeks...
Link to comment
Share on other sites

Here's your code as one array...
[code]<?php
$graphValues = array();
for ($i=1;$i<4;$i++)
     for ($j=1;$j<4;$j++)
          $graphValues[$i][$j] = $j;
echo '<pre>' . print_r($graphValues,true) . '</pre>';
for ($i=1;$i<4;$i++)
     for ($j=1;$j<4;$j++)
          echo '$graphValues[' . $i . '][' . $j . '] = ' . $graphValues[$i][$j] . '<br>';
?>[/code]
Which results in
[code]
Array
(
    [1] => Array
        (
            [1] => 1
            [2] => 2
            [3] => 3
        )

    [2] => Array
        (
            [1] => 1
            [2] => 2
            [3] => 3
        )

    [3] => Array
        (
            [1] => 1
            [2] => 2
            [3] => 3
        )

)

$graphValues[1][1] = 1
$graphValues[1][2] = 2
$graphValues[1][3] = 3
$graphValues[2][1] = 1
$graphValues[2][2] = 2
$graphValues[2][3] = 3
$graphValues[3][1] = 1
$graphValues[3][2] = 2
$graphValues[3][3] = 3
[/code]

Ken
Link to comment
Share on other sites

Ken

I'm not quite up to your last example, but I'm still trying to get my head around it...

meanwhile, I was proud of what my final solution was: (I marked the section below)

[code]
<?
header("Content-type: image/png");
$imgWidth=600;
$imgHeight=125;
// Create image and define colors
$image=imagecreate($imgWidth, $imgHeight);
$colorWhite=imagecolorallocate($image, 255, 255, 255);
$colorGrey=imagecolorallocate($image, 192, 192, 192);
$color[1]=imagecolorallocate($image, 0, 0, 255);
$color[2]=imagecolorallocate($image, 0, 255, 255);
$color[3]=imagecolorallocate($image, 255, 0, 255);
$color[4]=imagecolorallocate($image, 255, 0, 0);
$color[6]=imagecolorallocate($image, 25, 150, 0);
$color[5]=imagecolorallocate($image, 0, 255, 0);
$color[7]=imagecolorallocate($image, 255, 255, 255);

// Create border around image
// right vert
imageline($image, 599, 599, 599, 0, $colorGrey);
// bottom horiz
imageline($image, 0, 124, 599, 124, $colorGrey);
// top horiz
imageline($image, 599, 0, 0, 0, $colorGrey);
// left vert
imageline($image, 0, 0, 0, 599, $colorGrey);
// Create grid
for ($i=1; $i<30; $i++){
//H
imageline($image, $i*20, 0, $i*20, 600, $colorGrey);
//V
imageline($image, 0, $i*25, 600, $i*25, $colorGrey);}

$user="";
$host = "localhost";
$password="";
$database = "teknetix";
mysql_connect($host,$user,$password);
mysql_select_db($database);

$result = mysql_query("Select count(distinct `EVALUATOR`) as EVALUATOR From surveyresults
Where EVALUATOR not like '0018'
AND EVALUATOR not like '0311'");
IF ($row1 = mysql_fetch_array($result)){
    $COUNT=$row1['EVALUATOR'];
    }

$result1 = mysql_query("Select distinct `EVALUATOR` as EVALUATOR From surveyresults
where `EVALUATOR` <> '0018' AND `EVALUATOR` <> '0311'");
$c=1;

while ($row1 = mysql_fetch_array($result1)){
    $NAME[$c] = $row1['EVALUATOR'];
    $result0 = mysql_query("Select FNAME, LNAME from survey Where `ID` like '$NAME[$c]'");
$c++;
}

// HERE IS THE SECTION !!!!!!!

$tl=$c-1;
$c=1;
while ($c <= $tl){
     $col=$color[$c];
     $EVAL=$NAME[$c];
     $result2 = mysql_query("Select
     Avg(surveyresults.RATING) as RATING, surveyresults.`DATE` From surveyresults
     Where
     surveyresults.EVALUATOR = '$EVAL'
     Group By surveyresults.`DATE`
     Order By surveyresults.`DATE` Asc LIMIT 30");
     while ($row = mysql_fetch_array($result2)){
          $graphValues[$c][] = $row['RATING'];
      }
     // Create line graph
     for ($i=0; $i<30; $i++) {
     if (isset($graphValues[$c][$i+1])) {
            imageline($image, $i*20,
            (125-($graphValues[$c][$i])*25 + 12), ($i+1)*20,
            (125-($graphValues[$c][$i+1])*25 + 12), $color[$c]);
             }
      }
$c++;
}
imagepng($image);
imagedestroy($image);
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.