Reputation: 982
code:
$sql = "select company_name, salary, experience from company";
echo $sql;
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
print_r($row);
}
output
select company_name, salary, experience from company
Array ( [0] => xyz [company_name] => xyz [1] => 2 Lac - 3 Lac [salary] => 2 Lac - 3 Lac [2] => 2 Years - 3 Years [experience] => 2 Years - 3 Years )
In this code I have a table name company where I have multiple rows but when I execute this query it show me only first row data only I don't know why and Where I am doing wrong? How can I fix this issue ?
Thank You
Upvotes: 0
Views: 110
Reputation: 871
Try mysqli_fetch_assoc instead of mysqli_fetch_array
$res = [];
while($row = mysqli_fetch_assoc($result))
{
$res[] = $row;
}
print_r($res); exit;
Upvotes: 0
Reputation: 1715
You need to specify the row number in your while loop; row[0]
, row[1]
Upvotes: 1