marisha Posted August 4, 2011 Share Posted August 4, 2011 Hello All, I am using RGraph with Php to generate graphical report. They work together very well but now I have a logic issue. I am explaining it below Scenario - I have a multiple select drop down from which I can select multiple Buidling Numbers and Month <form name = "form1" method="post" > <select name="BuildingID[] name="buildingID" MULTIPLE> <option>Choose</option> <?//=$options?> </select> <select name="MonthID[]" name="Month" MULTIPLE> <option>Choose</option> <?//=$optionsMonth?> </select> </form> Step - Based on the number of buildings selected I have to fetch data from MySql database and make a data array for each building which will later on be represented as one line for each Building selected if($BuildingID) { $i = 1; for(;$i<=4;$i++) { foreach ($BuildingID as $t) { $buildingWithAddress = mysql_query(SELECT Metal_Quantity FROM `Physical_Plant_BuildingLevel_Data` WHERE BuildingID = $t AND Month IN ($MonthString) AND Year = $Year); [u][b]$data = array(); I NEED A NEW VARIABLE FOR EACH ITERATION. KIND OF DYNAMIC VARIABLES [/b][/u] $num_rows = mysql_num_rows($buildingWithAddress); while($nt=mysql_fetch_array($buildingWithAddress)) { $data[] = $nt["RR"]; } [u][b] $data_string = "[" . join(", ", $data) . "]"; I NEED A NEW STRING VARIABLE FOR EACH ITERATION. KIND OF DYNAMIC VARIABLES [/b][/u] } } } My Problem boils down to how can I make a array variable for each iteration of loop Link to comment https://forums.phpfreaks.com/topic/243776-rgraph-and-php-how-to-generate-dynamic-data-array-based-on-multiselect-dropdon/ Share on other sites More sharing options...
phpSensei Posted August 4, 2011 Share Posted August 4, 2011 You need to define a array which will contain other arrays, such as a multidimensional array, right before the while loop, then you can append the data into the array, and move on to the next one. Link to comment https://forums.phpfreaks.com/topic/243776-rgraph-and-php-how-to-generate-dynamic-data-array-based-on-multiselect-dropdon/#findComment-1251707 Share on other sites More sharing options...
marisha Posted August 4, 2011 Author Share Posted August 4, 2011 I have made progress bu using the logic of a two-dimensional array. I have not reached my goal yet I will keep updating as I make progress. $arrayData = array(); $i = 1; if($BuildingID) { foreach($BuildingID as $t) { $buildingWithAddress = mysql_query("SELECT Metal_Quantity FROM `Physical_Plant_BuildingLevel_Data` WHERE BuildingID = $t AND Month IN ($MonthString) AND Year = $Year;")or die("$db: ".mysql_error()); $num_rows = mysql_num_rows($buildingWithAddress); if($num_rows != 0) { while($nt=mysql_fetch_array($buildingWithAddress)) { $arrayData[$i][] = $nt["Metal_Quantity"]; } } $i++; } print_r($arrayData); } Link to comment https://forums.phpfreaks.com/topic/243776-rgraph-and-php-how-to-generate-dynamic-data-array-based-on-multiselect-dropdon/#findComment-1252070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.