Use PDO instead of mysqli. Make use of 'foreach'.