Re: assign value from fetch array

From: Date: Sat, 24 May 2014 17:56:30 +0000
Subject: Re: assign value from fetch array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-323362@lists.php.net to get a copy of this message
Thanks a million for helping and information, Regards, Iccsi, On Thu, May 22, 2014 at 11:52 AM, Shawn McKenzie <shawn@mckenzies.net>wrote: > The rows are indexed by number and then contain an array of the columns. > So this would work, but you probably want to loop over $rows: > > $rows = $sth->fetchAll(PDO::FETCH_ASSOC); > $name = $rows[0]['MyID']; > echo $name; > > When you fetch only one row it is just an array of columns: > > $row = $sth->fetch(PDO::FETCH_ASSOC); > $name = $row['MyID']; > echo $name; > > -Shawn > > > On Mon, May 19, 2014 at 6:57 PM, ICCSI <inungh@gmail.com> wrote: > >> I have following code to fetch data from database. >> I am able to print the array, but I got HTTP 500 error when I assign the >> array the value to echo the result. >> >> I think I am missing something between array and variable. >> >> Your help and information is great appreciated, >> >> Iccsi, >> >> >> $row = $sth->fetchAll(PDO::FETCH_ASSOC); >> print_r($row); >> print("\n"); >> $name = "{$row['MyID']}"; >> echo $name; >> > >

« previous php.general (#323362) next »