RE: [PHP] Building an array, kind of?
| From: | Boyd, Todd M. | Date: | Fri, 24 Oct 2008 16:30:52 +0000 |
| Subject: | RE: [PHP] Building an array, kind of? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282412@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Boyd, Todd M. [mailto:tmboyd1@ccis.edu]
> Sent: Friday, October 24, 2008 11:28 AM
> To: php-general@lists.php.net
> Subject: RE: [PHP] Building an array, kind of?
>
> > -----Original Message-----
> > From: Dan Shirah [mailto:mrsquash2@gmail.com]
> > Sent: Friday, October 24, 2008 9:52 AM
> > To: PHP LIST
> > Subject: [PHP] Building an array, kind of?
> >
> > TGIF?
> >
> > Apparently my brain isn't working this Friday.
> >
> > I'm trying to query my table to get the first 16 ID's. I then want
> > to assign the ID's to a variable and have them comma seperated.
> >
> > // My query to select the first 16 rows
> > $get_charges2 = "SELECT FIRST 16 * FROM history WHERE id = '$id";
> >
> > // Executing the query
> > $charge_result2 = ifx_query ($get_charges2, $connect_id);
> >
> > How would I assign the result to a variable?
> >
> > For instance, say my query returns rows like:
> >
> > 1234
> > 1235
> > 1236
> > 1237
> > 1238
> > 1239
> >
> > How would I go about putting that in a variable to equal
> > "1234,1235,1236,1237,1238,1239" ?
>
> I think someone's already used foreach() in an answer, but I don't see
> the point in building an array and then immediately joining it to a
> string and discarding the array...
>
> $t = '';
> foreach($resultset as $row)
> $t .= ',' . $row;
>
> Done and done.
Gah. Well, same amount of work, I guess, since you'll need to either
trim the first comma or add the first row before the foreach() loop.
Damn you, cat skin!
Todd Boyd
Web Programmer