Darkmatter5 Posted October 29, 2008 Share Posted October 29, 2008 Here's my code <?php include 'library/config.inc.php'; $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbnamemain); $query1=mysql_query("SELECT folder_id, fol_name FROM folders JOIN cabinets ON(cabinets.cabinet_id=folders.cabinet_id) WHERE cab_name='Bills' ORDER BY fol_name ASC ") or die(mysql_error()); $col_width=100/count($row=mysql_fetch_array($query1)); while($row=mysql_fetch_array($query1)) { $query2=mysql_query("SELECT bill_date_due, bill_amount FROM items WHERE folder_id=$row[folder_id] ORDER BY bill_date_due ASC ") or die(mysql_error()); $dataset=array(); while(list($date,$amt)=mysql_fetch_row($query2)) { $t=strtotime($date); $values=array ("year"=>date('Y',$t), "month"=>date('m',$t), "amount"=>$amt); $dataset[$values[month]]=$values[amount]; } $filename="images/graphs/$row[folder_id]$values[year].png"; if($dataset!=NULL) { ignore this code } echo "<table width='100%' align='center' border='1'> <tr>"; while($row=mysql_fetch_array($query1)) { echo "<th width='$col_width%'>$row[fol_name]</th>"; } echo "</tr></table>"; //else { echo "<i>Not data entered for this bill folder!</i>"; } //echo "<p>"; } mysql_close($conn); ?> Here's my table data: cabinets cabinet_id cab_name 2 bills folders folder_id fol_name cabinet_id 2 telephone 2 10 water and electric 2 15 internet 2 16 credit card statements 2 items item_id item_name bill_date_due bill_amount 9 tel01 2008-10-15 100 11 tel02 2008-11-15 120 12 tel03 2008-12-15 200 13 inter01 2008-10-16 50 14 inter02 2008-11-16 50 Now with this code and these tables, this is what is getting returned. <table width='100%' align='center' border='1'> <tr> <th width='25%'>Telephone</th> <th width='25%'>Water and Electric</th> </tr> </table> Why isn't it? <table width='100%' align='center' border='1'> <tr> <th width='25%'>credit card statements</th> <th width='25%'>internet</th> <th width='25%'>telephone</th> <th width='25%'>water and electric</th> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/130623-solved-help-with-array-and-output/ Share on other sites More sharing options...
Maq Posted October 29, 2008 Share Posted October 29, 2008 What's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/130623-solved-help-with-array-and-output/#findComment-677711 Share on other sites More sharing options...
sasa Posted October 29, 2008 Share Posted October 29, 2008 look coments in code <?php include 'library/config.inc.php'; $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbnamemain); $query1=mysql_query("SELECT folder_id, fol_name FROM folders JOIN cabinets ON(cabinets.cabinet_id=folders.cabinet_id) WHERE cab_name='Bills' ORDER BY fol_name ASC ") or die(mysql_error()); $col_width=100/count($row=mysql_fetch_array($query1)); // in vaiable $row is 1st row of data (credit card) // change to $col_width=100/mysql_num_rows($query1); while($row=mysql_fetch_array($query1)) { // in vaiable $row is 2nd row of data (internet) $query2=mysql_query("SELECT bill_date_due, bill_amount FROM items WHERE folder_id=$row[folder_id] ORDER BY bill_date_due ASC ") or die(mysql_error()); $dataset=array(); while(list($date,$amt)=mysql_fetch_row($query2)) { $t=strtotime($date); $values=array ("year"=>date('Y',$t), "month"=>date('m',$t), "amount"=>$amt); $dataset[$values[month]]=$values[amount]; } $filename="images/graphs/$row[folder_id]$values[year].png"; if($dataset!=NULL) { ignore this code } echo "<table width='100%' align='center' border='1'> <tr>"; // move this line before 1st while while($row=mysql_fetch_array($query1)) {// in vaiable $row is 3rd row of data (telephone) and goes to end // remove this line echo "<th width='$col_width%'>$row[fol_name]</th>"; } // and remove this too echo "</tr></table>"; //move this line after end of while loop //else { echo "<i>Not data entered for this bill folder!</i>"; } //echo "<p>"; } mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130623-solved-help-with-array-and-output/#findComment-677728 Share on other sites More sharing options...
Darkmatter5 Posted October 29, 2008 Author Share Posted October 29, 2008 thanks it worked! Quote Link to comment https://forums.phpfreaks.com/topic/130623-solved-help-with-array-and-output/#findComment-677756 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.