require 'db/connect.php';
if ($result = $db->query("SELECT last_name +' '+ first_name as full_name, bio FROM people")) {
if ($count = $result->num_rows) {
echo '<p>', $count , '</p>';
// while ($rows = $result->fetch_object()) {
// print_r($rows);
// echo '<br/>';
// }
while ($rows = $result->fetch_object()) {
echo $rows->full_name, ' ' , $rows->bio, '<br />';
}
$result->free();
}
} else {
die($db->error);
}
The database table people contains two rows of data where the columns are id, first_name, last_name, bio and created.
row 1: id=1, first_name=kelly, last_name='wafukho', bio=computer scientist.
row 2: id=2, first_name=gonzaga, last_name='situma', bio=graphic designer.
When the query below is run it gives me 0 computer scientist for row 1 and 0 graphic designer for row 2. What could be the reason for this? is the problem with my sql syntax or the php handles objects? Am using the mysql database.