Chris G wrote:
> Hi all
>
> Having a prob with a php script...
>
> 3 arrays
>
> $datay1=array(140,110,50,60);
>
> $datay2=array(35,90,190,190);
>
> $datay3=array(20,60,70,140);
>
> which have to be passed to a class like this
>
> $gbarplot = new GroupBarPlot(array($bplot1,$bplot2,$bplot3));
>
> if I get data from a database, how can I automatically increment the $datay
>
> arrays..... for instance
>
> currently with my loop that follows, I am only creating one array
>
> ($data1y) - but I now need to create various from user input.
>
> $query = "SELECT rep_value_perc FROM report_values WHERE rep_l_per_id =
>
> '$_GET[per_id]'";
>
> $result = mysql_query($query) or die (mysql_error());
>
> while($line = mysql_fetch_array($result)) {
>
> $data1y[] = $line['rep_value_perc'];
>
> }
>
> This gives me just the one array from the above example, $datay1. How would
>
> you dynamically create the all of the above arrays?
>
> At present the $_GET[per_id] is only one value $_GET[per_id] = 2
>
> What happens when it becomes more than one, like $_GET[per_id] = array
>
> (1,2,34,4,561,334)
>
> If I need to assign each one of the $_GET[per_id] a new $data array
> variable
>
> in the loop above how would you do it?
>
> Am I making sense?
>
> Thanks to anyone that reads this...
>
> Regards
>
> Chris
>
I'm going to attempt to summarise what you said, or my interpretation of it.
You want to create a dynamic list of variables based on the users input,
those variables happen to be arrays.
I would suggest creating a data array. This array will contain a series
of arrays built from the user input. The following psudo code will
achieve this.
foreach ($user_input_array as $user_input) {
$data_member = array(); # Create an empty array
Do SQL query stuff
foreach ($sql_results as $sql_member) {
$data_member[] = $sql_member;
}
$data[] = $data_member;
}
You can now do your function call as
$gbarplot = new GroupBarPlot($data);
And now a bit of bonus advice. The SQL query that you provided earlier
has a giant SQL injection attack problem. I'd recomend reading a little
about SQL injection attacks and getting it patched up.
David
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php