Invalid Argument why?

Invalid Argument why?

am 16.07.2009 21:41:37 von tmiller

Why is this an invalid argument?

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

echo $inType,'
';}

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: Invalid Argument why?

am 16.07.2009 21:47:10 von 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,'
';}
>
> 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: Invalid Argument why?

am 16.07.2009 21:53:38 von kyle.smith

--------------020203030405090307080003
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Miller, Terion wrote:
> Why is this an invalid argument?
>
> foreach(($row['inType']) as $inType){
>
> echo $inType,'
';}
>
> 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 . '
';
}


HTH,
Kyle

--------------020203030405090307080003--

Re: Invalid Argument why? (RESOLVED)

am 16.07.2009 21:56:40 von tmiller

Actually this ended up doing what I needed:

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


On 7/16/09 2:53 PM, "Kyle Smith" wrote:

Miller, Terion wrote:

Why is this an invalid argument?

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

echo $inType,'
';}

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 =3D whatever_your_rows_come_from();

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


HTH,
Kyle



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

Re: Invalid Argument why?

am 16.07.2009 22:09:38 von Martin Scotta

--0016e645fae854f09f046ed840c4
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

foreach iterates over an array or a object (see Traversable ).
If you pass anything different he complains


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

On Thu, Jul 16, 2009 at 4:53 PM, Kyle Smith wrote:

> Miller, Terion wrote:
>
>> Why is this an invalid argument?
>>
>> foreach(($row['inType']) as $inType){
>>
>> echo $inType,'
';}
>>
>> 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 . '
';
> }
>
>
> HTH,
> Kyle
>



--
Martin Scotta

--0016e645fae854f09f046ed840c4--