RE: [PHP-DB] Return Array from Function - SOLVED
| From: | Hutchins, Richard | Date: | Thu, 26 Sep 2002 20:43:40 +0000 |
| Subject: | RE: [PHP-DB] Return Array from Function - SOLVED | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-22035@lists.php.net to get a copy of this message | ||
John Holmes pointed out to me that I had made a stupid error by starting my
variable names with a number. Cardinal no-no. I know better. Really.
That solved the parse error. Another error popped up after that stating that
the variable $levelones was not a valid resource whenever I tried to
manipulate it. I assigned the results of the function call to another
variable ($stuff=getLevelOnes($docnum)) and the script works now. Must be
that $levelones is an out-of-scope variable on the calling page, thus the
need to assign the results of the function call to a local variable.
Maybe my pain can save you some. ;)
Thanks for the help.
> -----Original Message-----
> From: Dave Smith [mailto:DavidSmith@byu.net]
> Sent: Thursday, September 26, 2002 4:31 PM
> To: Hutchins, Richard
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] Return Array from Function
>
>
> Try single-quotes instead of double (' instead of "). Could be an
> interpolation issue.
>
> --Dave
>
> On Thu, 26 Sep 2002, Hutchins, Richard wrote:
>
> > Can somebody tell me what I might be doing wrong in the
> code below? I'm
> > trying to use a function to perform an often-used db query
> and return the
> > resulting resource to the calling script. I keep getting
> this error though:
> >
> > Parse error: parse error, unexpected T_LNUMBER, expecting
> T_VARIABLE or '$'
> > in c:\spidey\public\addleveltwo.php on line 51
> >
> > I've looked and looked, but I can't find what could be
> causing a parse
> > error. Most likely, I've just been looking at it for too
> long. Any fresh
> > eyes available?
> >
> > <?php
> > include("../protected/getContent.php");
> >
> > getLevelOnes($docnum); //user-defined function from
> included file.
> > Definition appears after this snippet.
> >
> > $num=mysql_num_rows($levelones);
> >
> > if($num<1)
> > {
> > echo("There is no level one (Section) content for this
> > document in the database.");
> > exit();
> > }
> >
> > while($row=mysql_fetch_array($levelones))
> > {
> > $1contentID=$row["1contentID"];
> > $parentID=$row["parentID"];
> > $1child=$row["childID"];
> > $1content=$row["1content"];
> > $1ordinal=$row["ordinal"];
> >
> > echo("<tr><td>".$1content."</td><td><a
> > href=\"contentMgr.php?docnum=".$docnum."\"
> > target=\"_right\">Add</a></td></tr>");
> > }
> > ?>
> >
> > <?php
> > function getLevelOnes($docnum)
> > {
> > $sql="SELECT 1contentID, parentID, childID, 1content,
> 1ordinal FROM
> > levelone WHERE 1contentID='$docnum'";
> > $levelones=mysql_query($sql)
> > or die(mysql_error());
> > return $levelones;
> > }
> > ?>
> >
> >
> >
>
> --
> ,-._.-._.-._.-._.-.
> `-. ,-'
> .----------------------. | |
> | Cool nerds use ASCII | | |
> | art at the bottom of | | |
> | their emails. | | |
> | | ,';".________.-.
> | | ;';_' )]
> | | ; `-|
> |
. T- |
> `----------------------._ \ | |
> `-; | |
> |..________..-|
> /\/ |________..|
> ,'`./ >,( |
> \_.-|_/,-/ ii | |
> ."' -/
> .-"""|| |
> /`^"-; | ||____|
> / / `.__/ | ||
> / | ||
> | ||
>