Page 1 of 1

database wrapper

Posted: Thu Jul 19, 2007 4:55 am
by shivam0101
when writing query for select statement,

Code: Select all

function Select($tablename)
{
  $query='SELECT * FROM tablename';
  while($fetch=mysql_fetch_array($query))
  {
   $fetched_arr=$fetch;
  }
}

usage:

Code: Select all

$data=Select('table')
if the number of record is 1 i have to use $data[0], if its more than 1 record, i have to use $data to display results. How to write a better query so it can be handled in same way on both occassions?

Posted: Thu Jul 19, 2007 4:58 am
by feyd
Your function returns nothing. $data[0] will create an error.