Jump to content

RGraph and Php (How to generate dynamic data array based on MultiSelect Dropdon)


marisha

Recommended Posts

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

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);
	}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.