Re: Re: Has element of array been initialized?
| From: | Rob Adams | Date: | Tue, 08 Apr 2003 23:40:19 +0000 |
| Subject: | Re: Re: Has element of array been initialized? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142977@lists.php.net to get a copy of this message | ||
"Ben Edwards" <ben@videonetwork.org> wrote in message
news:5.1.1.6.2.20030409002444.03435ff8@mail.videonetwork.org...
> Guess I need to give a bit more context.
>
> The code below is used to update the database. It is run when a form with
> multiple records is submitted. The array $product_code contains the codes
> of the products and $seq the order they are to be displayed.
>
> for Example:-
>
> $product_code[1] = "ER", $seq[1] = 10
> $product_code[2] = "TY", $seq[1] = Unititialised
>
>
> Problem is if the user blanks out the $seq field the element of the array
> douse not seem to be set.
>
> if ( $action == "Save" ) {
>
> $count = count( $product_code );
>
> for( $index=1; $index <= $count; ++$index ) {
Just a thought here. If you're not actually assigning the key of 1 -
whatever to the array, but letting the array fill as it will, the first
element will be 0 and the last will be count($array) - 1. In that case,
your for loop should be:
for($index = 0; $index < $count; $index++)
>
> if ( isset( $seq[$index]) ) {
> $seq = "'".$seq[$index]."'";
> } else {
> $seq = "NULL";
> }
>
> echo(
> "update products ".
> "set seq=$seq ".
> "where code='".$product_code[$index]."'" );
> }
>
> $action = "list";
>
> }
>
> I get the followig error:-
>
> Notice: Uninitialized string offset: 3 in
This offset of 3 might confirm my assumption. Are there 3 elements in the
array right now?
> d:\wwwroot\cultureshop\list_products.php on line 412
>
>
> At 17:19 08/04/2003 -0600, Rob Adams wrote:
>
>
> >"Ben Edwards" <ben@videonetwork.org> wrote in message
>
> >>news:5.1.1.6.2.20030408235826.0344e170@mail.videonetwork.org...
> > > I am trying to see if elements of a number indexed array are set, i.e.
> > > something like:-
> > >
> > > if ( isset( $seq[$index]) ) {
> > > echo $seq[$index]."<br>";
> > > }
> >
> >The only error I get when running this is when $index is undefined. I
can
> >call
> >isset($seq[whatever number you please here])
> > without getting an error.
> >
> > >
> > > Except in this case isset gives an error. How do i 'ask' if the
element
> > > has been initialized?
> > >
> > > Ben
> > >
> > >
> > > ****************************************************************
> > > * Ben Edwards Tel +44 (0)117 968 2602 ICQ 42000477 *
> > > * Critical Site Builder
> > > http://www.criticaldistribution.com *
> > > * online collaborative web authoring content management system *
> > > * Get alt news/views films online
> > > http://www.cultureshop.org *
> > > * i-Contact Progressive Video
> > > http://www.videonetwork.org *
> > > * Fun corporate graphics
> > > http://www.subvertise.org *
> > > * Bristol Indymedia
> > > http://bristol.indymedia.org *
> > > * Bristol's radical news
> > > http://www.bristle.org.uk *
> > > ****************************************************************
> > >
> >
> >
>
>---------------------------------------------------------------------------
-
> >----
> >
> >
> > >
> > > ---
> > > Outgoing mail is certified Virus Free.
> > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > Version: 6.0.465 / Virus Database: 263 - Release Date: 25/03/2003
> > >
> >
> >
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >
> >---
> >Incoming mail is certified Virus Free.
> >Checked by AVG anti-virus system (http://www.grisoft.com).
> >Version: 6.0.465 / Virus Database: 263 - Release Date: 25/03/2003
>
> ****************************************************************
> * Ben Edwards Tel +44 (0)117 968 2602 ICQ 42000477 *
> * Critical Site Builder http://www.criticaldistribution.com
> *
> * online collaborative web authoring content management system *
> * Get alt news/views films online http://www.cultureshop.org
> *
> * i-Contact Progressive Video http://www.videonetwork.org
> *
> * Fun corporate graphics http://www.subvertise.org
> *
> * Bristol Indymedia http://bristol.indymedia.org
> *
> * Bristol's radical news
> http://www.bristle.org.uk *
> ****************************************************************
>
----------------------------------------------------------------------------
----
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.465 / Virus Database: 263 - Release Date: 25/03/2003
>
-- Rob