RE: [PHP-DEV] foreach
| From: | Rose, Billy | Date: | Thu, 25 Apr 2002 17:00:49 +0000 |
| Subject: | RE: [PHP-DEV] foreach | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-83330@lists.php.net to get a copy of this message | ||
I feel like an idiot, I overlooked the *_fetch__array(). It's been a long
week...
Billy Rose
wrose@loislaw.com
> -----Original Message-----
> From: Gabriel Ricard [mailto:gabe@sumorai.net]
> Sent: Thursday, April 25, 2002 11:53 AM
> To: Rose, Billy
> Cc: php-dev@lists.php.net
> Subject: Re: [PHP-DEV] foreach
>
>
> This is neither a problem with PHP nor FreeTDS. From the manual:
>
> " sybase_fetch_array() is an extended version of
> sybase_fetch_row(). In
> addition to storing the data in the numeric indices of the
> result array,
> it also stores the data in associative indices, using the
> field names as
> keys. "
>
> Therefore each row contains duplicates of each value. Use
> sybase_fetch_row() instead.
>
> And, btw, this question really belongs on the php-general list. ;)
>
> - Gabriel
>
> Rose, Billy wrote:
> > Environment:
> >
> > Apache 2.0.35
> > PHP 4.2.0RC2
> > FreeTDS used in place of Sybase libraries to connect to
> MS SQL 2000
> > RedHat Linux 7.1
> > PII 233
> >
> > Problem:
> >
> > Using foreach retrieves a duplicate of each database column.
> >
> > Code tested:
> >
> > <html>
> > <head>
> > <title>Test</title>
> > </head>
> > <body>
> > <?
> > $link = sybase_connect($dbhost,$dbuser,$dbpass)
> > or die("Error connecting");
> > sybase_select_db($dbname)
> > or die("Error selecting database");
> > $result = sybase_query($query)
> > or die("Error running query");
> > print("<table border='0' width='100%'
> > cellpadding='0'
> cellspacing='4'>\n");
> > while ($row = sybase_fetch_array($result)) {
> > print("<tr>\n");
> > foreach ($row as $col) {
> > print("<td>".$col."</td>\n");
> > }
> > print("</tr>\n");
> > }
> > print("</table>\n");
> > sybase_free_result($result);
> > sybase_close($link);
> > ?>
> > </body>
> > </html>
> >
> > Is this a PHP issue, or a FreeTDS problem?
> >
> > Billy Rose
> > wrose@loislaw.com
> >
>
>
>
> --
> Gabriel Ricard
> gabe@sumorai.net
>