Reputation: 16147
I am creating a script where I need to retrieve several information in a database. I am expecting to receive these datas
I need to get those 2 track paths. but all I get is the first result and that's it. I've run my SQL script in phpmyadmin it is completely showing all of the datas that I needed. but when I execute that query in PHP. it only returns to me the first result. Here's my script
public static function find_user_tracks($id){
global $mySQL;
$sql = "SELECT * FROM `tracks` WHERE account_id = {$id}";
$result_set = $mySQL->query($sql);
return $result_set->fetch_assoc();
}
And here's the code I call to print the results
$row = Track::find_user_tracks($id);
echo "{$row['track_path']}<br>";
but all I receive is only the first path.
Upvotes: 0
Views: 177
Reputation: 160963
You need to do a loop to return all records.
public static function find_user_tracks($id){
global $mySQL;
$sql = "SELECT * FROM `tracks` WHERE account_id = {$id}";
$result_set = $mySQL->query($sql);
$ret = array();
while($row = $result_set->fetch_assoc()) {
$ret[] = $row;
}
return $ret;
}
Upvotes: 2