Jump to content


Photo

array using database


  • Please log in to reply
1 reply to this topic

#1 ncix007

ncix007
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 11 April 2006 - 05:41 AM

hi,
i got stuck in some where in my code:
i have created database and inserted the information as needed

i want to
display the information as an array as follows:
$admission= array();

///example written manaully

$admission[0] = array("name" => "ram", "m" => "best","id" => "item", "u1" => "");
$admission[1] = array("name" => "kam", "m" => "computer","id" => "code", "u1" => "");
$admission[2] = array("name" => "john", "m" => "jam","id" => "sku", "u1" => "");
$admission[3] = array("name" => "aanita","m" => "circuit","id" => "oid", "u1" => "");

///

i have 4 field in database table as name, m, id, u1
i want to parse the list in the above manner
can any body help me

regards
ncix007


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 11 April 2006 - 06:26 AM

$admissions = array();
$sql = "SELECT name, m, id, u1 FROM tablename";
$res = mysql_query ($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($res)) {
    $admissions[] = $row;
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users