AV1611 Posted April 27, 2006 Share Posted April 27, 2006 Well, I guess you can't do this:Any suggestions???$graphValues$c[]=$row['RATING'];[code]while ($c <= $tl){$EVAL=$NAME[$c];$result2 = mysql_query("SelectAvg(surveyresults.RATING) as RATING, surveyresults.`DATE` From surveyresultsWheresurveyresults.EVALUATOR = '$EVAL'AND DATE_SUB(NOW(),INTERVAL 30 DAY)<=DATEGroup Bysurveyresults.`DATE`Order Bysurveyresults.`DATE` Asc");while ($row = mysql_fetch_array($result2)){ $graphValues$c[]=$row['RATING'];}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/ Share on other sites More sharing options...
inztinkt Posted April 27, 2006 Share Posted April 27, 2006 while ($row...){$graphValues$c [b].=[/b] $row['RATING'];}should put each rating into the variable Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31422 Share on other sites More sharing options...
kenrbnsn Posted April 27, 2006 Share Posted April 27, 2006 Why don't you think you can't do that? Errors? What did you get, what did you expect to get?Maybe what you want is[code]<?php $graphValues[$c][]=$row['RATING']; ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31423 Share on other sites More sharing options...
AV1611 Posted April 27, 2006 Author Share Posted April 27, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31432 Share on other sites More sharing options...
kenrbnsn Posted April 27, 2006 Share Posted April 27, 2006 Why don't you do it this way: [code]<?php $graphValues[$c][]=$row['RATING']; ?>[/code]You will have one 2-diminsional array instead of many different arrays. It will be much easier to code.Ken Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31455 Share on other sites More sharing options...
Zane Posted April 27, 2006 Share Posted April 27, 2006 you'd do it this way...for dynamic variables[code]$arrays = "graphValues" . $c;$$arrays[]=$row['RATING'];[/code]but yeah kenrbnsn is righta multi-dim array would work more smoothly Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31479 Share on other sites More sharing options...
AV1611 Posted April 28, 2006 Author Share Posted April 28, 2006 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:123123123//(here is the loop version)<?phpfor($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... Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31522 Share on other sites More sharing options...
kenrbnsn Posted April 28, 2006 Share Posted April 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31556 Share on other sites More sharing options...
AV1611 Posted April 28, 2006 Author Share Posted April 28, 2006 KenI'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 vertimageline($image, 599, 599, 599, 0, $colorGrey);// bottom horizimageline($image, 0, 124, 599, 124, $colorGrey);// top horizimageline($image, 599, 0, 0, 0, $colorGrey);// left vertimageline($image, 0, 0, 0, 599, $colorGrey);// Create gridfor ($i=1; $i<30; $i++){//Himageline($image, $i*20, 0, $i*20, 600, $colorGrey);//Vimageline($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 surveyresultsWhere 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 surveyresultswhere `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] Quote Link to comment https://forums.phpfreaks.com/topic/8573-creating-an-array/#findComment-31727 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.