fareedreg Posted October 15, 2011 Share Posted October 15, 2011 I am getting trouble since today morning from the associative array. Actually I am using phpgraphlib.php to create line graph. Every thing is working fine.. I can easily create graph if i type value direct in the associative array like this. include('phpgraphlib.php'); include('connect.php'); mysql_select_db($Db, $link); $query = "select colone,coltwo from graphtemp"; $result = mysql_query($query,$link); $nro=mysql_num_rows($result); $row=mysql_fetch_assoc($result); while ($row = mysql_fetch_assoc($result)) { $A[] = $row['colone']; $C[]= $row['coltwo']; } $data=array("$A[0]"=>$C[0],$A[1]=>$C[1],$A[2]=>$C[2],$A[3]=>$C[3], $A[4]=>$C[4],$A[5]=>$C[5]); $graph = new PHPGraphLib(750,400); $graph->addData($data); here i am mentioning only 6 number of rows. but problem arise when i do not know the number of rows in the table. How can i accept the values from the mysql table when i do not know the exact number of row.. Please help Quote Link to comment https://forums.phpfreaks.com/topic/249184-php-array-help/ Share on other sites More sharing options...
Philip Posted October 15, 2011 Share Posted October 15, 2011 <?php $data = array(); while ($row = mysql_fetch_assoc($result)) { $data[$row['colone']] = $row['coltwo']; } Quote Link to comment https://forums.phpfreaks.com/topic/249184-php-array-help/#findComment-1279630 Share on other sites More sharing options...
fareedreg Posted October 15, 2011 Author Share Posted October 15, 2011 Sorry Thanks for support.. Now its working... Quote Link to comment https://forums.phpfreaks.com/topic/249184-php-array-help/#findComment-1279632 Share on other sites More sharing options...
Philip Posted October 15, 2011 Share Posted October 15, 2011 Then the sample code you gave is not working.... are you sure your query is working? PS - you're calling fetch_assoc outside of the loop, which will essentially skip getting the first row (since the loop overwrites $row) Quote Link to comment https://forums.phpfreaks.com/topic/249184-php-array-help/#findComment-1279634 Share on other sites More sharing options...
fareedreg Posted October 15, 2011 Author Share Posted October 15, 2011 great website.. great help.. great people... thanks Quote Link to comment https://forums.phpfreaks.com/topic/249184-php-array-help/#findComment-1279638 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.