Get values from mysql database and store in php array -


this question has answer here:

i working on project php , mysql need values mysql database , store them array.

code:

$con=new mysqli("localhost","root","","databse"); $sql="select name data"; $result= array(); $result=$con->query($sql); 

how store data in php array?

here example of how it!

 //mysqli information      $db_host     = "localhost";     $db_username = "username";     $db_password = "password";      //connect mysqli database (host/username/password)     $connection = mysqli_connect($db_host, $db_username, $db_password) or die("error " . mysqli_error());      //select mysqli dabatase table     $db = mysqli_select_db($connection, "table") or die("error " . mysqli_error());     $sql = mysqli_query($connection, "select * data");     while($row = mysqli_fetch_array($sql)) {    $names[] = $row['name']; } 

edit: print results out using

print_r($names);  

or

foreach($names $name) { echo "$name"; } 

good luck!


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -