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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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