---
title: "Getting SQL result into an array"  
description: "Getting SQL result into an array"  
author: "Anonymous User"  
published: 2013-07-08  
updated: 2013-07-08  
canonical: https://www.mindstick.com/forum/1262/getting-sql-result-into-an-array  
category: "json"  
tags: ["json"]  
reading_time: 1 minute  

---

# Getting SQL result into an array

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs)!\
I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to get a [MySQL](https://www.mindstick.com/articles/12156/what-is-mysql) [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) like "[SELECT](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) * FROM [sales](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store)" into an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) that looks like this:\
**$[data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) = array(** **array('[Date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner)', 'Sales'),** **array('June 25', 12.25),** **array('June 26', 8.00)** **);****\**I tried it with a [while loop](https://www.mindstick.com/forum/34579/while-loop-in-python) but it didn't work. How can i do this?\
Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi Garry!\
Try this\

```
$query = "SELECT * FROM sales";$data = array();$data[] =array('Date', 'Sales');if ($result = $mysqli->query($query)) {            while ($line = $result->fetch_assoc())     {                // line contain an associative array with "Date" and "Sales"          $data[] = array($line['Date'], $line['Sales']);    }}$result->free();
```

\
I hope it helpful for you!


---

Original Source: https://www.mindstick.com/forum/1262/getting-sql-result-into-an-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
