Jump to content


Photo

Create Array from mysql result


  • Please log in to reply
2 replies to this topic

#1 oracle259

oracle259
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 25 September 2006 - 07:28 PM

How do i create an array from a mysql result. So far i have tried this

while ($res = mysql_fetch_array($result, MYSQL_BOTH) {

$link[] = $res[item];

}

echo $link[];

but that doesnt seem to work.

any help would be appreciated.

#2 Barand

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

Posted 25 September 2006 - 07:44 PM

instead of echo $link, you need to loop thru the array
foreach ($link as $item) echo $item.'<br/>';

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

#3 Gaoshan

Gaoshan
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 26 September 2006 - 01:40 AM

The array is created automatically by mysql_fetch_array. To step through that array just use:
while ($row = mysql_fetch_array($result)) {
    echo $row[0], $row[1], $row[2];  
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users