Get values from mysql database and store in php array -
this question has answer here:
- get array of rows mysqli result 1 answer
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
Post a Comment