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
https://forums.phpfreaks.com/topic/105401-am-at-a-wall/
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
https://forums.phpfreaks.com/topic/105401-am-at-a-wall/#findComment-539816
Share on other sites

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.