Jelle Van de Vliet
Jelle Van de Vliet

Reputation: 81

select query is not returning a result in php

I'm executing following simple sql query:

SELECT people_picture, people_gender FROM people LIMIT 1 which in phpmyadmin gives a result.

My php code is the following:

    $query = "SELECT people_picture, people_gender FROM people LIMIT 1";
    $result = mysqli_query($con,$query);
    $row = mysql_fetch_assoc($result);
    $row1 = mysql_fetch_array($result);

    print_r($row1);
    print_r($row);

It doesn't give an error, but it just doesn't do anything.

Upvotes: 0

Views: 760

Answers (2)

Volkan
Volkan

Reputation: 2210

You are mixing mysqli and mysql interfaces thats why you got stuck:

Try this please:

$con = mysqli_connect($host, $user, $pass, $dbase);
if(!$con){
    echo 'Connection failed : '.mysqli_connect_error();
    exit(0);
}
$query = "SELECT people_picture, people_gender FROM people LIMIT 1";
$result = mysqli_query($con,$query);
if(!$result){
   echo 'Query failed : '.mysqli_error();
   exit(0);
} 
$row = mysqli_fetch_assoc($result);  //  mysql_fetch_assoc was the problem
print_r($row);

Upvotes: 1

Freeman
Freeman

Reputation: 1190

Use mysqli_fetch_assoc instead

Upvotes: 1

Related Questions