Re: Creating dynamic variables and assigning values in a while statement
| From: | Nicole Amashta | Date: | Fri, 19 Apr 2002 18:10:16 +0000 |
| Subject: | Re: Creating dynamic variables and assigning values in a while statement | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-13197@lists.php.net to get a copy of this message | ||
>>> $counter = "0";
This line may work in your code, but if you are assigning numbers, you don't
need to put quotes around them since they are numbers and not strings.
If you then want to use that number as part of a string, do like you did:
$temp="ydata$counter";
or do like so:
$temp="ydata " . $counter;
I don't use the $$ thing, so I'm not sure what you are doing there.
SO, what is the error you are getting? Or what is/isn't happening with your
code? Can you be more specific?
--
Nicole Amashta
Web Application Developer
www.aeontrek.com
"Robert Trembath" <robert@ishoptech.com> wrote in message
news:000201c1e7b5$bdcdc300$4001a8c0@roblaptop...
> Good morning everyone,
>
> Kinda got stuck here. Must be brain dead this morning. I'm trying to
> loop thru a results set from a mysql query that will always return an
> array of 13 results. I need to loop thru using a while statement and
> create dynamic variables $temp1 - $temp13 and $tempcolor1 - $tempcolor13
> to assign values to each of these variables as I loop thru. Here's the
> code, please review and advise, suggest whatever. This script is used to
> build a line graph in php from the data in the $temp variables.
>
> $counter = "0";
> file://loop thru wells to create line plots
> while( $row = mysql_fetch_array( $query ) )
> {
> file://define global
> $temp="ydata$counter";
> global $$temp;
> $tempcolor="ydata$counter";
> global $$tempcolor;
> // Create the linear plot
> $ydata = explode(",", $row[CurveData]);
> $$temp = $ydata;
>
> file://Set Line Plot Color
> $lineplot->SetColor("$color[$counter]");
> $$tempcolor = $lineplot;
>
> file://add 1 to counter
> $counter = $counter + 1;
> }
>
> file://define lines
> $lineplot0=new LinePlot($temp0);
> $lineplot1=new LinePlot($temp1);
> $lineplot2=new LinePlot($temp2);
> $lineplot3=new LinePlot($temp3);
> $lineplot4=new LinePlot($temp4);
> $lineplot5=new LinePlot($temp5);
> $lineplot6=new LinePlot($temp6);
> $lineplot7=new LinePlot($temp7);
> $lineplot8=new LinePlot($temp8);
> $lineplot9=new LinePlot($temp9);
> $lineplot10=new LinePlot($temp10);
> $lineplot11=new LinePlot($temp11);
> $lineplot12=new LinePlot($temp12);
>
> file://set colors
> $lineplot0->SetColor("$tempcolor0");
> $lineplot1->SetColor("$tempcolor1");
> $lineplot2->SetColor("$tempcolor2");
> $lineplot3->SetColor("$tempcolor3");
> $lineplot4->SetColor("$tempcolor4");
> $lineplot5->SetColor("$tempcolor5");
> $lineplot6->SetColor("$tempcolor6");
> $lineplot7->SetColor("$tempcolor7");
> $lineplot8->SetColor("$tempcolor8");
> $lineplot9->SetColor("$tempcolor9");
> $lineplot10->SetColor("$tempcolor10");
> $lineplot11->SetColor("$tempcolor11");
> $lineplot12->SetColor("$tempcolor12");
>
> file://ad lines
> $graph->Add($lineplot0);
> $graph->Add($lineplot1);
> $graph->Add($lineplot2);
> $graph->Add($lineplot3);
> $graph->Add($lineplot4);
> $graph->Add($lineplot5);
> $graph->Add($lineplot6);
> $graph->Add($lineplot7);
> $graph->Add($lineplot8);
> $graph->Add($lineplot9);
> $graph->Add($lineplot10);
> $graph->Add($lineplot11);
> $graph->Add($lineplot12);
>
> HELP!!!!
>
> --------------------------
> D. Robert Trembath
> Chief Software Engineer
> Bacterial BarCodes Inc.
> e|robert@bacbarcodes.com
>
>