PDA

View Full Version : get length givin' me hard time


bassouma86
03-07-2004, 07:41 PM
hey there

i was trying 2 use the count() to get the length of an array.

it should be sth like variable = count(ArrayName);

but i have a problem with my IIS server that makes me access the array (an HTML list of options using sth like

foreach ( $_GET["products"] as $value )

so the count() should be variable = count($_GET["products"]);

Is this right or I'm i on the wrong track here ???

cause anyway it ain't workin' :mad:

btw the purpose 4 gettin' the length of my array of options is to know when the array is empty so that i could handle that case cause i have a script that runs like a charm when i choose one option or more but when i choose none it makes an error :confused:

so if there's a way around I'd appriciate it ;)

thx in advance & good night

Abelius
03-07-2004, 10:46 PM
"length" is the word in order to get the length of an array in ActionScript, but I am not sure you are talking about it...

freddycodes
03-08-2004, 12:39 AM
Yeah he is talking about PHP here.

So whats the problem count() doesn't work? If it is null, then php will not know its an array. How about if

if($_GET["products"] != null && sizeof($_GET["products"]) > 0 )

bassouma86
03-08-2004, 05:36 AM
hey there

I integrated freddycodes' code into mine & came up with this :


if($_GET["products"] != null && sizeof($_GET["products"]) > 0 )
{
foreach ( $_GET["products"] as $value )
{
print "<li>".$value."<br>\n";
}
}
else
{
print "EMPTY";
}


The products array is an array of HTML multiple options list.

it works fine when i select an option or more but when i choose none of 'em it outputs an error Notice: Undefined index: products in e:\inetpub\wwwroot\poll\data.php on line 13
but still prints EMPTY :confused:

I'm still lost in here
plz advice :)
thx