jkkenzie Posted May 13, 2008 Share Posted May 13, 2008 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. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 13, 2008 Share Posted May 13, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.