RE: [PHP] [] operator not supported for strings
| From: | Ford, Mike [LSS] | Date: | Fri, 27 Jun 2003 10:34:30 +0000 |
| Subject: | RE: [PHP] [] operator not supported for strings | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-153091@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Andrew McCombe [mailto:andrew@euperia.com]
> Sent: 27 June 2003 11:18
>
> Can anyone tell me why i'm getting this error?
>
> Fatal error: [] operator not supported for strings in
> c:\inetpub\wwwroot\Iweb-sites\Exp\menu2.php on line 41
>
> [code]:
>
>
> $rst2=sql_call("SELECT * FROM tmenu WHERE parent=".$r['id']);
> // now have array of corporate, entertainment and identity
>
> for ($i=0; $i < mysql_num_rows($rst2); $i++) {
> $r=mysql_fetch_array($rst2);
> $level2[$i] = $r['name'];
$r['name'] will be a string -- and so, therefore, will $level2[$i] be.
> $rst3 = sql_call("SELECT * FROM tmenu WHERE parent=".$r['id']);
>
> while ($a=mysql_fetch_array($rst3)) {
> $level2[$i][] = $a['name']; // giving error here
$level2[$i] is still a string, and the [] notation when applied to a string
selects an individual character -- but you haven't specified which
character, so this is an error.
Did you mean the first assignment to $level2[$i] to start a new array that
you later add to in the loop? In which case you might want to do
$level2[$i] = array($r['name']);
If you meant something else, you probably need to tell us exactly what it is
you're trying to do, so we can suggest accurate solutions.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211