omkara
omkara

Reputation: 982

Mysqli Select query not working properly

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

Answers (2)

Andrii Sukhoi
Andrii Sukhoi

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

Jeremy John
Jeremy John

Reputation: 1715

You need to specify the row number in your while loop; row[0], row[1]

Upvotes: 1

Related Questions