I'm working on a project where I have to write a function to get all records from a table which will return array of objects.
I've written a function to get a single record from table and working fine..but to get all records i'll have to write while loop..how would I store data in array and how would I display all data...?
Below is function to get a single record
Code: Select all
$sql = "select * from student where id = 1";
$getData = $db->getRecord($sql);
function getRecord($sql)
{
$result = mysql_query($sql) or die(mysql_error());
$data_set = mysql_fetch_array($result);
return $data_set;
}