Answer the question
In order to leave comments, you need to log in
How to get PHP array of data from db?
Suppose there is a table with the following values:
id name age
1 John 21
2 Jack 16
3 James 21
4 Jerry 22
Submit a MySQL query
$con->query("SELECT name FROM tbl_name WHERE age='21'");
echo $arr[0];//John
echo $arr[1];//James
Answer the question
In order to leave comments, you need to log in
$query = $con->query("SELECT name FROM tbl_name WHERE age='21'");
$arr = $query->fetchAll();
echo $arr[0]['name']; //John
echo $arr[1]['name']; //James
// OR
$query = $con->query("SELECT name FROM tbl_name WHERE age='21'");
while ($row = $query->fetch()) {
echo $row['name'];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question