Re: accessing data from an array within an array.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,

worked it out, thankyou.


On 7 May 2011, at 16:57, <admin@xxxxxxxxxxxxxxxxxxx> wrote:

> I would suggest you print out the array to get a better understanding of the
> structure first.
> 
> Print_r('<PRE>');
> Print_r($array);
> Print_r('<PRE>');
> 
> 
> You can foreach over the $array['row'] 
> 
> Foreach($array['row'] as $key=>$values)
> {
> 	Echo $values.PHP_EOL;
> }
> 			
> 
> 
> 
> Richard L. Buskirk
> 
> -----Original Message-----
> From: Adam Preece [mailto:ad84@xxxxxxxxxxxxxxxx] 
> Sent: Saturday, May 07, 2011 11:37 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  accessing data from an array within an array.
> 
> hello all.
> 
> im trying to make a function that fetches all rows in the database and
> stores each row (Array) within an array.
> 
> so the code is as follows: 
> 
> public function fetch_all($table_name,$order = "DESC"){
> 			$array['row'] = array();
> 			strtoupper($order);
> 			$query = "SELECT * FROM `{$table_name}` ORDER BY id
> {$order}";
> 			$result = $this->gen_query($query);
> 			while($row = $this->fetch_assoc($result)){
> 				$array['row'][] = $row;
> 			}
> 			
> 			if($this->sql_error_check($result)){
> 				return $array;
> 			}
> 		}
> 
> this returns (ill just paste 1 row for the sake of the email length:
> 
> Array ( [row] => Array ( [0] => Array ( [id] => 9 [name] => TESTER [title]
> => TESTER [heading] => TESTER [text] =>
> 
> TESTER
> [gallery_id] => 0 [meta_desc] =>
> 
> TESTER
> [meta_keywords] => TESTER [meta_author] =>
> 
> 
> 
> TESTER
> [page_id] => 0 [date_time] => 2011-05-07 06:49:39 [image] =>
> [user_access_id] => 1 ) 
> 
> How do i access each array within the array and throw out the data for each
> one.
> 
> im pretty confused on this one.
> 
> any help would be appreciated.
> 
> Adam
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux