print sql query result as an array php

Solutions on MaxInterview for print sql query result as an array php by the best coders in the world

showing results for - "print sql query result as an array php"
Yannic
13 Jan 2020
1<?php
2$connection = mysqli_connect( 'localhost', 'root', 'dbPass' );
3if ( !$connection ) {
4    die( 'Database Connection Failed' . mysqli_error( $connection ) );
5}
6$select_db = mysqli_select_db( $connection, 'sample_login' );
7if ( !$select_db ) {
8    die( 'Database Selection Failed' . mysqli_error( $connection ) );
9}
10$query = 'SELECT * FROM login';
11
12$result = mysqli_query( $connection, $query );
13$stack = array();
14while( $row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) ) {
15    array_push( $stack, $row );
16}
17//Stop the code here if you just want it as a PHP array 
18//(Don't forget the PHP closing tag) if you do that though
19//If you want to carry on and convert the PHP array to a JavaScript array
20//Include the rest of this code
21
22$theArray = json_encode( $stack );
23print_r( $theArray );
24?>
25<script>
26var theArray = <?php echo $theArray ?> ;
27console.log(theArray);
28</script>
29  
queries leading to this page
php mysql query return arrayphp mysql fetch column data as arrayselect 2a from table where name 3d php arrayget id from database fetch array phphow to get array from sql in phpphp fetch arrayphp while mysql fetch arrayfetch array from database in phpselect query in array phpreturn mysql arrayhow to get data from fetch arrayphp mysql query get arrayhow to use php to get an array of results from sql queryselect array php mysqlfetching data from array phpphp sql query arraysql fetch array boththe numbers in php array from database rowshow to list results of mysql query in an array phpis the row variable a speciual variable in php for mysql fetch arrayphp get sql result arrayphp echo sql arraywhat will you get by using mysql assoc resulttype in mysql fetch array 28 29 function 3fget array of sql select phpquery get result array phpconn query to array phpget mysql result as array phpget array from result set sql phpi have an array 2c i want to check i value of my sql result against the array and fetch resultsphp mysql array to tablefetch data in array mysql array functionmysql fetch array 28 24 2c mysql both 29print sql array phpphp sql query to arraymysql fetch arraymysql print query in array phpget last row in while 28 24row 3d mysqli fetch array 28 24result1 29 29 7bphp while fetch arraymysql php array resultarray of queries phpwhile 28 24r 3d mysqli fetch array 28 24q 29 29how to fetch array data in feild in phpphp select query to arrayphp array mysql queryphp get database value in arrayphp return rows from mysql as arrayphp print array mysqlphp print mysql result in arrayquery 28 24sql 2carray 29 php functionphp mysql result set to arrayoutput array row once phpstore sql query result in array phpphp query to arraymysql fetch array phpwhile 28 24row 3d mysql fetch array 28 24result 29 29fetch data from sql and show as array phpretrievomg values from fetch arrayphp mysql result to number arrayphp sql query return arraymysql fetch arraymysql php get database row into arrayphp get array from sqlwhile row fetch arrayhow to fetch all data from database in php is an arrayphp mysql display query as an arrayfetch result php mysqli fetch array select row from arrayfetch data in an arrayfetch data from php arrayphp mysql array selectmysql fetch array php 7mysqli fetch array search by idhow to make fetch array i phpmysql fetch array mysql both 2c mysqli assoc 29my sql array value print in phpfetch arraprint sql query result as an array phpfetch mysql data in php arrayphp query result to arrayphp mysql arrayphp get query string as arrayphp getting data from database as an arrayget array from mysql in phparray fetch sa ve all values in php myslqi fetch arraypre mysql all rows arrayfor loop fetch array phpphp array mysqlhow to pus sql fetch data in an arrat in phpreturn array mssql fetch array 24row 3dmysql fetch array 28 24sql 29 3bphp sql into arrayecho sql result as array phpquery array in phpphp mysql result to arraysql fetch array list phpsave mysql fetch array name array phphow to fetch from mysql and put in arrayphp fetch mysql result to arrayphp place sql result to arrayphp mysql while fetch rowmysql fetch array 28 29array php mysql query fetch arrayphp get first sql result as arrayarray data in mysql querymysql fetch array to array phpfetch an arraysql query response to array phpfetch arrayphp query arraymysql to php arraysphp sql to arrayhow to load array in php mysql queryhowo to show sql array result in phpfetch as an arrayphp get data from mysql to arrayphp get info from a mysql arrayhow to fetch array data only in phphow to display data of fetched arrayphp return query result as arrayprint sql query result as an array php