Is there any way to write an efficient code better than this.
try{
$sql = "SELECT * FROM device.monitor WHERE del_stat IS NULL AND id = ?";
$q = connection::$db->prepare($sql);
$q -> bindValue(1, $id, PDO::PARAM_INT);
$q ->execute();
$row = $q->rowCount();
if ($row == 0) {
echo 'no records found.';
}else{
while ($row = $q->fetch(PDO::FETCH_ASSOC))
{
$mon = $row['mon_brand'];
$ay= $row['id'];
$return[] = array($mon, $ay);
}
}
}catch (Exception $e) {
print "Error!:" . $e->getMessage();
}
because everytime I call the values I just do the following:
foreach ($view as $test)
{
$id = $test[1];
$brand = $test[0];
}
I wonder if there is another way of doing it like calling just automatically call the id and it will show its value.
Thank you in advance.