1

I'm trying to put proper values into appropriate cells but cannot figure it out
Let me show you what I'm trying to accomplish

Correct Output
Correct output
but instead it shows me that

Incorrect Output
Incorrect Output


So, I've began with a simple while loop to loop for records from a database for a selected date

$query = "SELECT DISTINCT dates FROM sample_table";
...

   $datesLetter = 'D';
   $valueIncrementId = 2;


       while($dates = $db->fetch_array($query))
       {

     ...

     $nextQuery = "SELECT c1.id, c1.value FROM values AS c1 
        LEFT JOIN sample_table AS c2 
        ON c1.id = c2.val_id WHERE c2.date = $date";

        $valueIncrementId = 2;

        while($v = $db->fetch_array($nextQuery))
        {
          $objPHPExcel->setActiveSheetIndex()->setCellValue($datesLetter.$valueIncrementId, $v['value']);

          $valueIncrementId++;
        }

      $datesLetter++;
   }


Thanks in advance
Regards, Bes

Besmir Sadiku
  • 75
  • 1
  • 7
  • Are you resetting `$valueIncrementId` anywhere inside your loops? – Mark Baker Jul 07 '15 at 14:04
  • Yes (also edited the question), inside first loop but still same output. – Besmir Sadiku Jul 07 '15 at 15:25
  • Well if you are resetting it to row 2, then it will start repopulating the rows from row 2 on every change of date.... what is there about the data for a given date that tells you it should be for a specific sample number? – Mark Baker Jul 07 '15 at 15:27
  • Well, I understand that but let's assume that on the first date it returns me only the values for 1st and 2nd sample but on the second date it returns me values for samples from 3rd to 5th, so instead of starting from row2 it should start from row4 (E4) – Besmir Sadiku Jul 07 '15 at 15:33
  • There are cases that dates returns values for each sample, but on this occasion it return only two values (sample1, sample2) on the first date and on second date returns three values (sample3, sample4, sample5) but on different rows, hopes that it makes sense – Besmir Sadiku Jul 07 '15 at 15:37
  • What, in your select statement, tells you which sample number it should be? – Mark Baker Jul 07 '15 at 15:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82707/discussion-between-besmir-sadiku-and-mark-baker). – Besmir Sadiku Jul 08 '15 at 13:07

0 Answers0