Jump to content

help with while statement


Darkmatter5

Recommended Posts

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);
               
               $que_fols=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());
               while($row1=mysql_fetch_array($que_fols)) {
                   echo "<b>$row1[fol_name] ($row1[folder_id])</b><br>";
                   $que_years=mysql_query("SELECT DISTINCT item_id, folders.folder_id, fol_name, MID(bill_date_due,1,4) as year
                                           FROM items
                                           JOIN folders ON(folders.folder_id=items.folder_id)
                                           JOIN cabinets ON(cabinets.cabinet_id=folders.cabinet_id)
                                           WHERE cab_name='Bills'
                                           AND folders.folder_id=$row1[folder_id]
                                           ORDER BY fol_name ASC, year ASC
                                           ") or die(mysql_error());
                   while($row2=mysql_fetch_array($que_years)) {
                       $que_data=mysql_query("SELECT bill_date_due, bill_amount
                                              FROM items
                                              WHERE folder_id=$row1[folder_id]
                                              AND item_id=$row2[item_id]
                                              ORDER BY bill_date_due ASC
                                              ") or die(mysql_error());
                       $dataset=array();
                       while(list($date,$amt)=mysql_fetch_row($que_data)) {
                           $t=strtotime($date);
                           $values=array ("year"=>date('Y',$t),
                                          "month"=>date('m',$t),
                                          "amount"=>$amt);
                           $dataset[$values[month]]=$values[amount];
                       }
                       $filename="images/graphs/$row1[folder_id]$row2[year].png";
                       //echo "<a href='$filename'> $row2[year]</a>";
                       print_r($row2);
                   }
                   /*if($dataset!=NULL) { echo " <a href='$filename'>$row2[year]</a>"; }
                   else { echo "<i>No items exist in this bill folder!</i>"; }*/
                   echo "<p>";
               }
               
               mysql_close($conn);
             ?>

 

Here's what the print_r shows.

Credit Card statements (14)

 

Internet (15)

Array ( [0] => 13 [item_id] => 13 [1] => 15 [folder_id] => 15 [2] => Internet [fol_name] => Internet [3] => 2008 [year] => 2008 ) Array ( [0] => 14 [item_id] => 14 [1] => 15 [folder_id] => 15 [2] => Internet [fol_name] => Internet [3] => 2008 [year] => 2008 )

 

Telephone (2)

Array ( [0] => 15 [item_id] => 15 [1] => 2 [folder_id] => 2 [2] => Telephone [fol_name] => Telephone [3] => 2007 [year] => 2007 ) Array ( [0] => 9 [item_id] => 9 [1] => 2 [folder_id] => 2 [2] => Telephone [fol_name] => Telephone [3] => 2008 [year] => 2008 ) Array ( [0] => 11 [item_id] => 11 [1] => 2 [folder_id] => 2 [2] => Telephone [fol_name] => Telephone [3] => 2008 [year] => 2008 ) Array ( [0] => 12 [item_id] => 12 [1] => 2 [folder_id] => 2 [2] => Telephone [fol_name] => Telephone [3] => 2008 [year] => 2008 )

 

Water and Electric (10)

 

Where should I place the "echo "<a href='$filename'> $row2[year]</a>";" line so that the output would be?

 

Credit Card statements (14)

 

Internet (15)

2008

 

Telephone (2)

2007 2008

 

Water and Electric (10)

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.