1

I am a novice in PHP. I have the following snippet from my PHP Code

  $select = "SELECT budgetname,SUM(budgetamount) AS budget,sqlitebudgetid FROM budget WHERE budgettype = 'INCOME' AND budgetaccount = '$budgetAccount' AND budgetuser = '$userID' AND budgetdate BETWEEN '$fromDate' AND '$toDate' GROUP BY BudgetName ASC";

 $result = mysqli_query($con, $select); 

       while($row = mysqli_fetch_array($result)) {             

        $rowIncomeBudgetLabels[] = $row["budgetname"];          

        $rowIncomeBudgetAmounts = array($row["budget"],$row["budget"], row["sqlitebudgetid"]);          

       } 

I have tried to put the last part $rowIncomeBudgetAmounts into the following array but the result only display the first line.

I tried as below but id not working :

  $data = array($rowIncomeBudgetAmounts);

Want to put to an array as below : so that each line is displayed as a separate sub array. Please help.

$data = array(  array( 255, 100, 100 ),
              array( 100, 255, 100 ),
              array( 100, 100, 255 ),
              array( 255, 255, 100 ),
            );

EDIT >>

I am getting the following results ; instead of several lines - I am only getting the first line. On the graph all descriptions are showing but without all corresponding figures.

enter image description here

PERFECT : This is the result I wanted : Thanks @Ultrazz008

enter image description here

4
  • please provide array you are getting from select query.... Commented Jul 11, 2017 at 8:51
  • Select query gives me a result table with 3 columns ie(budgetname, budget and sqlitebudgetid) - I want as an example to put all digits from all columns as shown in the $data array above. Commented Jul 11, 2017 at 9:03
  • 1
    @IshmaelChibvuri Edit your post and show us the result that you are getting. so based on this result we can suggest you a proper way to handle this Commented Jul 11, 2017 at 9:06
  • I have edited.. Hopefully it make sense now :) Commented Jul 11, 2017 at 9:13

1 Answer 1

1

You should change the line from:

$rowIncomeBudgetAmounts = array($row["budget"],$row["budget"], row["sqlitebudgetid"]);

to:

$rowIncomeBudgetAmounts[] = array($row["budget"],$row["budget"], $row["sqlitebudgetid"]);

And you will get array of array data, appended [] at the end of $rowIncomeBudgetAmounts, and the $ missing from the row["sqlitebudgetid"]

And after that use: $data = $rowIncomeBudgetAmounts; to get the:

array( array(), array(), array() ) - of your data.

Here's the way you wish it, and the code i posted in answer how it works:

http://ideone.com/2nuMyw

Sign up to request clarification or add additional context in comments.

1 Comment

You just don't need the $data = array($rowIncomeBudgetAmounts);, the code i posted and change this to $data = $rowIncomeBudgetAmounts; it should be the same array as you posted it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.