[PHP] Invalid Argument why?

2009-07-16 Thread Miller, Terion
Why is this an invalid argument?

 foreach(($row['inType']) as $inType){

echo $inType,'br';}

I am trying to output results from a data base that may have multiple
results for the same name

So trying to use an array and foreach that is the right track ...right?


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



Re: [PHP] Invalid Argument why?

2009-07-16 Thread Ashley Sheridan
On Thu, 2009-07-16 at 15:41 -0400, Miller, Terion wrote:
 Why is this an invalid argument?
 
  foreach(($row['inType']) as $inType){
 
 echo $inType,'br';}
 
 I am trying to output results from a data base that may have multiple
 results for the same name
 
 So trying to use an array and foreach that is the right track ...right?
 
 
I imagine $row is the array, and ['inType'] is an element of the array.
This is not how you use a foreach. Can you show where you are getting
$row from?

Thanks
Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Invalid Argument why?

2009-07-16 Thread Kyle Smith

Miller, Terion wrote:

Why is this an invalid argument?

 foreach(($row['inType']) as $inType){

echo $inType,'br';}

I am trying to output results from a data base that may have multiple
results for the same name

So trying to use an array and foreach that is the right track ...right?


  

Looks like you meant to do something like this:

// Always better to be plural when you have an array.
$rows = whatever_your_rows_come_from();

foreach($rows as $row)
{
   $inType = $row['inType'];
   echo $inType . 'br /';
}


HTH,
Kyle


Re: [PHP] Invalid Argument why? (RESOLVED)

2009-07-16 Thread Miller, Terion
Actually this ended up doing what I needed:

   $result = 
mysql_query($sql) or die(mysql_error());
   $header = false; 
 while($row = mysql_fetch_assoc($result)){  
   if(!$header){
   echo ($row['name']),'br';  
 echo 
($row['address']),'br';   
$header = true; 
} 
echo ($row['inDate']),'br';   
  echo ($row['inType']),'br'; 
echo ($row['notes']),'br';
 echo ($row['critical']),'br' ;   
  echo 
($row['cviolations']),'br';   
   }}


On 7/16/09 2:53 PM, Kyle Smith kyle.sm...@inforonics.com wrote:

Miller, Terion wrote:

Why is this an invalid argument?

 foreach(($row['inType']) as $inType){

echo $inType,'br';}

I am trying to output results from a data base that may have multiple
results for the same name

So trying to use an array and foreach that is the right track ...right?



Looks like you meant to do something like this:

// Always better to be plural when you have an array.
$rows = whatever_your_rows_come_from();

foreach($rows as $row)
{
$inType = $row['inType'];
echo $inType . 'br /';
}


HTH,
Kyle



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



Re: [PHP] Invalid Argument why?

2009-07-16 Thread Martin Scotta
foreach iterates over an array or a object (see Traversable ).
If you pass anything different he complains

?php

if( !is_scalar( $collection ) )
foreach( $collection as $element )
print_r( $element );

On Thu, Jul 16, 2009 at 4:53 PM, Kyle Smith kyle.sm...@inforonics.comwrote:

 Miller, Terion wrote:

 Why is this an invalid argument?

  foreach(($row['inType']) as $inType){

 echo $inType,'br';}

 I am trying to output results from a data base that may have multiple
 results for the same name

 So trying to use an array and foreach that is the right track ...right?




 Looks like you meant to do something like this:

 // Always better to be plural when you have an array.
 $rows = whatever_your_rows_come_from();

 foreach($rows as $row)
 {
   $inType = $row['inType'];
   echo $inType . 'br /';
 }


 HTH,
 Kyle




-- 
Martin Scotta