I AM A PHP SUPER NOOB.
I am trying to extract data using PHP from a MySQL db.
I want to take the 'PersonName' column and 'Count' column and place them into an array.
PHP Code (so far):
$result = mysqli_query($con, --SQL CODE HERE--);
while($row = mysqli_fetch_array($result))
{
$data = $row['colName'];
}
I have been using print_r to print out my $data and i have been getting results such as"Array ( [0] => Fred [Name] => Fred [1] => 11 [count(*)] => 11 )"
in my attempts. This format has not been working for me.
I want to obtain an array (or 2 arrays) that contain the data from the 2 columns mentioned above.
I need it to be in either of the following formats:
1. One-Array Solution: [['Fred', 3], ['Bob', 5], ['Ted', 10]]
2. Two-Array Solution: ['Fred', 'Bob', 'Ted'] & [3, 5, 10]
How should my PHP code be modified in order to bring data in from the database into the array formats that I am looking for?
$dataArray = array();
while($row = mysqli_fetch_array($result))
{
$dataArray[] = $row;
}
Display it this way in your HTML and you will understand how to use the data from the array
<?php print_r($dataArray); ?>