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;
}
The above code contains the result of a database query. The database looks like this:
So basically it will return to me a set of fields with values and then I'll get those values to use them for a certain page:
$row = Track::find_user_tracks($id);
if(!empty($row))
{
$track_paths = array();
$track_names = array();
$track_desc = array();
$track_ids = array();
$track_artist = array();
for($i = 0 ;$i<count($row);$i++)
{
$track_paths[] = $row[$i]['track_path'];
$track_ids[] = $row[$i]['track_id'];
$track_names[] = $row[$i]['track_name'];
$track_desc[] = $row[$i]['track_desc'];
$track_artist[] = $row[$i]['artist'];
}
echo "<h1> {$screename}'s Beats</h1>";
}
The $row
variable contains the result from the previous queries. I loop over $row
to extract every single bit of data like track_id
, track_name
, etc.
Now I am wondering: is there any way to make this cleaner or improve it?