print sql query result as an array php

<?php
$connection = mysqli_connect( 'localhost', 'root', 'dbPass' );
if ( !$connection ) {
    die( 'Database Connection Failed' . mysqli_error( $connection ) );
}
$select_db = mysqli_select_db( $connection, 'sample_login' );
if ( !$select_db ) {
    die( 'Database Selection Failed' . mysqli_error( $connection ) );
}
$query = 'SELECT * FROM login';

$result = mysqli_query( $connection, $query );
$stack = array();
while( $row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) ) {
    array_push( $stack, $row );
}
//Stop the code here if you just want it as a PHP array 
//(Don't forget the PHP closing tag) if you do that though
//If you want to carry on and convert the PHP array to a JavaScript array
//Include the rest of this code

$theArray = json_encode( $stack );
print_r( $theArray );
?>
<script>
var theArray = <?php echo $theArray ?> ;
console.log(theArray);
</script>
  

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
get array from result set sql php php get sql result array php sql query return array php echo sql array echo sql result as array php print sql array php mysql print query in array php i have an array, i want to check i value of my sql result against the array and fetch results pre mysql all rows array fetch result php php mysql result to number array php print mysql result in array php query result to array get mysql result as array php fetch data from php array php mysql query return array conn query to array php query fetch array $row=mysql_fetch_array($sql); php fetch mysql result to array fetch mysql data in php array while row fetch array array fetch sa ve all values in php myslqi_fetch_Array mysqli_fetch_array select row from array mysqli_fetch_array search by id query($sql,array) php function output array row once php how to fetch from mysql and put in array Query array in php php mysql result set to array php place sql result to array php return rows from mysql as array php array mysql how to get data from fetch array how to make fetch array i php fetch an array php get data from mysql to array php mysql while fetch row the numbers in php array from database rows mysql fetch_array fetch array php select query to array php mysql array select fetch data in an array get array of sql select php how to pus sql fetch data in an arrat in php how to fetch all data from database in php is an array how to fetch array data only in php how to load array in php mysql query while($row = mysql_fetch_array($result)) php mysql fetch column data as array get id from database fetch_array php how to use php to get an array of results from sql query mysql fetch array how to get array from sql in php how to fetch array data in feild in php fetch data in array return array mssql_fetch_array mysql_fetch_array php 7 php while fetch array php while mysql_fetch_array php sql query array php return query result as array php sql into array mysql_fetch_array() select query in array php fetch arra php sql query to array php fetch array retrievomg values from fetch array php query to array get last row in while($row = mysqli_fetch_array($result1)){ array of queries php how to display data of fetched array php get array from sql sql fetch array both mysql fetch array php for loop fetch array php php get database value in array array php mysql mysql array function is the row variable a speciual variable in php for mysql fetch array mysql_fetch_array MYSQL_BOTH, MYSQLI_ASSOC ) mysql_fetch_array($, MYSQL_BOTH) while ($r= mysqli_fetch_array($q)) mysql to php arrays What will you get by using MYSQL_ASSOC resulttype in mysql_fetch_array() function? array data in mysql query php query array php get first sql result as array sql fetch array list php php mysql array to table php mysql result to array php mysql array fetch as an array php getting data from database as an array save mysql_fetch_array name array php php get info from a mysql array fetching data from array php get array from mysql in php fetch data from sql and show as array php sql query response to array php fetch array from database in php php mysql query get array mysql fetch array to array php select array php mysql select * from table where name = php array mysql php get database row into array return mysql array php sql to array how to list results of mysql query in an array php print sql query result as an array php
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source