Jump to content

Am at a Wall!


jkkenzie

Recommended Posts

From below code, am able to get the $A[] AND $C[] for all countries BUT i want to get PER country and put in different variables . How do i go about it.

 


<?PHP
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("digitaldevidemt", $con);

$project = $_GET['project'];
$highestcountry = $_GET['highestcountry'];
//Get Countries within project
$result1 = mysql_query("SELECT DISTINCT country FROM tblcalc WHERE projectname='$project' ORDER BY id");
        $count=0;
	while($row1 = mysql_fetch_assoc($result1))
         {         
         $country[]= $row1['country'];  
	 $count++;
         }
//Get Data for each country: THIS IS WHERE I WANT FOR EACH COUNTRY TO BE PUT ON DIFFERENT VARIABLES	 

$count2=0;
While($count2<$count)
     {
        $result2 = mysql_query("SELECT Values_A, Values_C FROM tblcalc WHERE projectname='$project' AND country='$country[$count2]' ORDER BY id");
        while($row2 = mysql_fetch_assoc($result2))
        {  
        $A[] = $row2['Values_A'];  
         $C[] = $row2['Values_C']; 		           
        }

$count2++;

}	
  	mysql_close($con);

 

thanks in advance.

Link to comment
Share on other sites

If you just changed these two lines:

 

$A[] = $row2['Values_A'];  
$C[] = $row2['Values_C']; 		     

 

To:

 

$A[][] = $row2['Values_A'];  
$C[{$country[$count2]]}] = $row2['Values_C'];     

 

It should work. However, you dont need to be doing two queries. You could just do:

 

<?php
$sql = "SELECT country,Values_A,Values_C FROM tblcalc WHERE projectname='$project' ORDER BY id"
$result = mysql_query($sql) or die(mysql_error());
$A = array();
$C = array();
while(list($country,$a_val,$c_cal) = mysql_fetch_row($result)){
$A[$country] = $a_val;
$C[$country] = $c_val;
}
?>

 

Which would achieve the same, but with just the one query.

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.