Question about reading data I've created with , delimiter

Hello, could someone please show me how to do this.

In a single cell in a DB column, I can have multiple kinds of data
squeezed together delimited by a comma.

like .....
"datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
"

If I read that data and have it in a string like $datastring...... how
do I put it into a array situation? to access that data.... so if I
want to know what is in spot 5 only, and return back 'datayellow' for
instance, how do I do that? :-) I don't know if array is the right
word, I just want to be able to access any part of that string based
on the order it is in.

Thank you!

Rebecca
rebeccatre [ Mo, 16 Juli 2007 02:13 ] [ ID #1770052 ]

Re: Question about reading data I've created with , delimiter

rebeccatre [at] gmail.com wrote:
>
> Hello, could someone please show me how to do this.
>
> In a single cell in a DB column, I can have multiple kinds of data
> squeezed together delimited by a comma.
>
> like .....
> "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> "
>
> If I read that data and have it in a string like $datastring...... how
> do I put it into a array situation? to access that data.... so if I
> want to know what is in spot 5 only, and return back 'datayellow' for
> instance, how do I do that? :-) I don't know if array is the right
> word, I just want to be able to access any part of that string based
> on the order it is in.
>
> Thank you!
>
> Rebecca
>

Rebecca,

Try this in comp.databases.mysql - a MySQL newsgroup.

But before you do, google for "database normalization". MySQL has a
decent discussion on it, but some other sites may be better.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 16 Juli 2007 02:41 ] [ ID #1770053 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:41 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> rebecca... [at] gmail.com wrote:
>
> > Hello, could someone please show me how to do this.
>
> > In a single cell in a DB column, I can have multiple kinds of data
> > squeezed together delimited by a comma.
>
> > like .....
> > "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> > "
>
> > If I read that data and have it in a string like $datastring...... how
> > do I put it into a array situation? to access that data.... so if I
> > want to know what is in spot 5 only, and return back 'datayellow' for
> > instance, how do I do that? :-) I don't know if array is the right
> > word, I just want to be able to access any part of that string based
> > on the order it is in.
>
> > Thank you!
>
> > Rebecca
>
> Rebecca,
>
> Try this in comp.databases.mysql - a MySQL newsgroup.
>
> But before you do, google for "database normalization". MySQL has a
> decent discussion on it, but some other sites may be better.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> ==================

Jerry is right -- you should fix your database first.

Having said that, have a look at the explode() function in PHP -- it
will take a delimited string and turn it into an array.

<http://www.php.net/explode>
zeldorblat [ Mo, 16 Juli 2007 02:47 ] [ ID #1770054 ]

Re: Question about reading data I've created with , delimiter

..oO(rebeccatre [at] gmail.com)

>Hello, could someone please show me how to do this.
>
>In a single cell in a DB column, I can have multiple kinds of data
>squeezed together delimited by a comma.
>
>like .....
>"datagreen,datablue,dataorange,datawhite,datayellow,datared ,datablue, ...
>"

You'll run into trouble with such a design. Read about database
normalization (the above violates the first normal form already).

>If I read that data and have it in a string like $datastring...... how
>do I put it into a array situation?

http://php.net/explode

Micha
Michael Fesser [ Mo, 16 Juli 2007 02:49 ] [ ID #1770055 ]

Re: Question about reading data I've created with , delimiter

Usually I get a answer in alt.php concerning MYSQL :-) :-)

I've reposted the question below, I have a very large and complex
environment, and this is just the thing I need to do. Can someone
please show a working example? How does the explode() command help me
pull back #5 data slot? Thank you for your patience and anyone can
help that would be great.


-----------

Hello, could someone please show me how to do this.

In a single cell in a DB column, I can have multiple kinds of data
squeezed together delimited by a comma.

like .....
"datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
"

If I read that data and have it in a string like $datastring...... how
do I put it into a array situation? to access that data.... so if I
want to know what is in spot 5 only, and return back 'datayellow' for
instance, how do I do that? :-) I don't know if array is the right
word, I just want to be able to access any part of that string based
on the order it is in.

Thank you!

Rebecca
rebeccatre [ Mo, 16 Juli 2007 02:57 ] [ ID #1770056 ]

Re: Question about reading data I've created with , delimiter

<?
$string='datagreen,datablue,dataetc';
$ary = explode($string, ',');
foreach($ary as $a)
{
echo "<p>".$a."</p>\t";
}
?>
explode() creates an array by breaking a string on deliminators (boundries).
Running the above in php should output what's below in the client browser.

datagreen
datablue
dataetc

HTH
Vince

<rebeccatre [at] gmail.com> wrote in message
news:1184544785.598523.147040 [at] q75g2000hsh.googlegroups.com.. .
>
>
> Hello, could someone please show me how to do this.
>
> In a single cell in a DB column, I can have multiple kinds of data
> squeezed together delimited by a comma.
>
> like .....
> "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> "
>
> If I read that data and have it in a string like $datastring...... how
> do I put it into a array situation? to access that data.... so if I
> want to know what is in spot 5 only, and return back 'datayellow' for
> instance, how do I do that? :-) I don't know if array is the right
> word, I just want to be able to access any part of that string based
> on the order it is in.
>
> Thank you!
>
> Rebecca
>
Vince Morgan [ Mo, 16 Juli 2007 02:59 ] [ ID #1770057 ]

Re: Question about reading data I've created with , delimiter

..oO(rebeccatre [at] gmail.com)

>Usually I get a answer in alt.php concerning MYSQL :-) :-)
>
>I've reposted the question below, I have a very large and complex
>environment, and this is just the thing I need to do. Can someone
>please show a working example? How does the explode() command help me
>pull back #5 data slot? Thank you for your patience and anyone can
>help that would be great.

Did you actually read the manual page for explode()? Using it is pretty
easy - you feed a string to it and get an array back. The 5th element of
your string would be the 4th element in the array (zero-based indexes).

Micha
Michael Fesser [ Mo, 16 Juli 2007 03:09 ] [ ID #1770058 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> .oO(rebecca... [at] gmail.com)
>
> >Usually I get a answer in alt.php concerning MYSQL :-) :-)
>
> >I've reposted the question below, I have a very large and complex
> >environment, and this is just the thing I need to do. Can someone
> >please show a working example? How does the explode() command help me
> >pull back #5 data slot? Thank you for your patience and anyone can
> >help that would be great.
>
> Did you actually read the manual page for explode()? Using it is pretty
> easy - you feed a string to it and get an array back. The 5th element of
> your string would be the 4th element in the array (zero-based indexes).
>
> Micha

Thank you Micha & Vince, this is kinda the theory that I hope to
figure out. I do understand there is a explode command, but there
isn't sufficient examples out there (or at least I have not found one
yet) related to answer what I would like.

The code example kindly posted by Vince is helpful to understand-see
the explode() command unravel the string, but it doesn't solve the
question I proposed. :( I want to be able to only print part of that
string on demand (5th slot for example).... am I getting close? ;)
rebeccatre [ Mo, 16 Juli 2007 03:15 ] [ ID #1770059 ]

Re: Question about reading data I've created with , delimiter

<?
$string='datagreen,datablue,dataetc';
$ary = explode($string, ',');
echo "<p>".$ary[2]."</p>\t";

?>
Should output:

dataetc

HTH
Vince
<rebeccatre [at] gmail.com> wrote in message
news:1184548548.346329.169130 [at] r34g2000hsd.googlegroups.com.. .
> On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> > .oO(rebecca... [at] gmail.com)
> >
> > >Usually I get a answer in alt.php concerning MYSQL :-) :-)
> >
> > >I've reposted the question below, I have a very large and complex
> > >environment, and this is just the thing I need to do. Can someone
> > >please show a working example? How does the explode() command help me
> > >pull back #5 data slot? Thank you for your patience and anyone can
> > >help that would be great.
> >
> > Did you actually read the manual page for explode()? Using it is pretty
> > easy - you feed a string to it and get an array back. The 5th element of
> > your string would be the 4th element in the array (zero-based indexes).
> >
> > Micha
>
> Thank you Micha & Vince, this is kinda the theory that I hope to
> figure out. I do understand there is a explode command, but there
> isn't sufficient examples out there (or at least I have not found one
> yet) related to answer what I would like.
>
> The code example kindly posted by Vince is helpful to understand-see
> the explode() command unravel the string, but it doesn't solve the
> question I proposed. :( I want to be able to only print part of that
> string on demand (5th slot for example).... am I getting close? ;)
>
Vince Morgan [ Mo, 16 Juli 2007 03:29 ] [ ID #1770060 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:29 pm, "Vince Morgan" <vinharAtHereoptusnet.com.au>
wrote:
> <?
> $string='datagreen,datablue,dataetc';
> $ary = explode($string, ',');
> echo "<p>".$ary[2]."</p>\t";
>
> ?>
> Should output:
>
> dataetc
>
> HTH


Zweet Vince --- you are the best
rebeccatre [ Mo, 16 Juli 2007 03:31 ] [ ID #1770061 ]

Re: Question about reading data I've created with , delimiter

..oO(rebeccatre [at] gmail.com)

>The code example kindly posted by Vince is helpful to understand-see
>the explode() command unravel the string, but it doesn't solve the
>question I proposed. :( I want to be able to only print part of that
>string on demand (5th slot for example).... am I getting close? ;)

No offense intended, but could it be that you're lacking some very
basics like how to access array elements or to print something out?

Micha
Michael Fesser [ Mo, 16 Juli 2007 03:43 ] [ ID #1770062 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:29 pm, "Vince Morgan" <vinharAtHereoptusnet.com.au>
wrote:
> <?
> $string='datagreen,datablue,dataetc';
> $ary = explode($string, ',');
> echo "<p>".$ary[2]."</p>\t";
>
> ?>
> Should output:
>
> dataetc
>
> HTH
> Vince<rebecca... [at] gmail.com> wrote in message
>
> news:1184548548.346329.169130 [at] r34g2000hsd.googlegroups.com.. .
>
> > On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> > > .oO(rebecca... [at] gmail.com)
>
> > > >Usually I get a answer in alt.php concerning MYSQL :-) :-)
>
> > > >I've reposted the question below, I have a very large and complex
> > > >environment, and this is just the thing I need to do. Can someone
> > > >please show a working example? How does the explode() command help me
> > > >pull back #5 data slot? Thank you for your patience and anyone can
> > > >help that would be great.
>
> > > Did you actually read the manual page for explode()? Using it is pretty
> > > easy - you feed a string to it and get an array back. The 5th element of
> > > your string would be the 4th element in the array (zero-based indexes).
>
> > > Micha
>
> > Thank you Micha & Vince, this is kinda the theory that I hope to
> > figure out. I do understand there is a explode command, but there
> > isn't sufficient examples out there (or at least I have not found one
> > yet) related to answer what I would like.
>
> > The code example kindly posted by Vince is helpful to understand-see
> > the explode() command unravel the string, but it doesn't solve the
> > question I proposed. :( I want to be able to only print part of that
> > string on demand (5th slot for example).... am I getting close? ;)

Vince, maybe I missed something in running this, but I actually got a
empty return :(
rebeccatre [ Mo, 16 Juli 2007 03:45 ] [ ID #1770063 ]

Re: Question about reading data I've created with , delimiter

Sorry Rebecca. I should have looked more closely. The parameters for
'explode()' are reversed.
$ary = explode($string, ','); should be as below.
$ary = explode(',', $string);

My appologies,
Vince

<rebeccatre [at] gmail.com> wrote in message
news:1184550344.620682.189780 [at] o61g2000hsh.googlegroups.com.. .
> On Jul 15, 8:29 pm, "Vince Morgan" <vinharAtHereoptusnet.com.au>
> wrote:
> > <?
> > $string='datagreen,datablue,dataetc';
> > $ary = explode($string, ',');
> > echo "<p>".$ary[2]."</p>\t";
> >
> > ?>
> > Should output:
> >
> > dataetc
> >
> > HTH
> > Vince<rebecca... [at] gmail.com> wrote in message
> >
> > news:1184548548.346329.169130 [at] r34g2000hsd.googlegroups.com.. .
> >
> > > On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> > > > .oO(rebecca... [at] gmail.com)
> >
> > > > >Usually I get a answer in alt.php concerning MYSQL :-) :-)
> >
> > > > >I've reposted the question below, I have a very large and complex
> > > > >environment, and this is just the thing I need to do. Can someone
> > > > >please show a working example? How does the explode() command help
me
> > > > >pull back #5 data slot? Thank you for your patience and anyone can
> > > > >help that would be great.
> >
> > > > Did you actually read the manual page for explode()? Using it is
pretty
> > > > easy - you feed a string to it and get an array back. The 5th
element of
> > > > your string would be the 4th element in the array (zero-based
indexes).
> >
> > > > Micha
> >
> > > Thank you Micha & Vince, this is kinda the theory that I hope to
> > > figure out. I do understand there is a explode command, but there
> > > isn't sufficient examples out there (or at least I have not found one
> > > yet) related to answer what I would like.
> >
> > > The code example kindly posted by Vince is helpful to understand-see
> > > the explode() command unravel the string, but it doesn't solve the
> > > question I proposed. :( I want to be able to only print part of that
> > > string on demand (5th slot for example).... am I getting close? ;)
>
> Vince, maybe I missed something in running this, but I actually got a
> empty return :(
>
Vince Morgan [ Mo, 16 Juli 2007 03:52 ] [ ID #1770064 ]

Re: Question about reading data I've created with , delimiter

In our last episode,
<1184544785.598523.147040 [at] q75g2000hsh.googlegroups.com>,
the lovely and talented rebeccatre [at] gmail.com
broadcast on comp.lang.php:



> Hello, could someone please show me how to do this.

> In a single cell in a DB column, I can have multiple kinds of data
> squeezed together delimited by a comma.

> like .....
> "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> "

Yes, you could do the same thing with a file-based data system. The point
of using a database is to avoid this sort of thing.

> If I read that data and have it in a string like $datastring...... how
> do I put it into a array situation? to access that data.... so if I
> want to know what is in spot 5 only, and return back 'datayellow' for
> instance, how do I do that? :-) I don't know if array is the right
> word, I just want to be able to access any part of that string based
> on the order it is in.

The best stituation would have been to set up your database properly
(1 cell = 1 datum). As it is, you can use explode on the string which
gives you a one-dimensional array, and the 5th item on the list will
have index 4 in the array (because indices start at 0).

> Thank you!

> Rebecca

--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 554 days to go.
Owing to massive spam from googlegroups, I do not see most posts from there.
Lars Eighner [ Mo, 16 Juli 2007 08:23 ] [ ID #1770065 ]

Re: Question about reading data I've created with , delimiter

rebeccatre [at] gmail.com wrote:
>
> Hello, could someone please show me how to do this.
>
> In a single cell in a DB column, I can have multiple kinds of data
> squeezed together delimited by a comma.
>
> like .....
> "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> "
>
> If I read that data and have it in a string like $datastring...... how
> do I put it into a array situation? to access that data.... so if I
> want to know what is in spot 5 only, and return back 'datayellow' for
> instance, how do I do that? :-) I don't know if array is the right
> word, I just want to be able to access any part of that string based
> on the order it is in.
>
> Thank you!
>
> Rebecca
>

Rebecca,

Try this in comp.databases.mysql - a MySQL newsgroup.

But before you do, google for "database normalization". MySQL has a
decent discussion on it, but some other sites may be better.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex [at] attglobal.net
==================
Jerry Stuckle [ Mo, 16 Juli 2007 02:41 ] [ ID #1770087 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:41 pm, Jerry Stuckle <jstuck... [at] attglobal.net> wrote:
> rebecca... [at] gmail.com wrote:
>
> > Hello, could someone please show me how to do this.
>
> > In a single cell in a DB column, I can have multiple kinds of data
> > squeezed together delimited by a comma.
>
> > like .....
> > "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> > "
>
> > If I read that data and have it in a string like $datastring...... how
> > do I put it into a array situation? to access that data.... so if I
> > want to know what is in spot 5 only, and return back 'datayellow' for
> > instance, how do I do that? :-) I don't know if array is the right
> > word, I just want to be able to access any part of that string based
> > on the order it is in.
>
> > Thank you!
>
> > Rebecca
>
> Rebecca,
>
> Try this in comp.databases.mysql - a MySQL newsgroup.
>
> But before you do, google for "database normalization". MySQL has a
> decent discussion on it, but some other sites may be better.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck... [at] attglobal.net
> ==================

Jerry is right -- you should fix your database first.

Having said that, have a look at the explode() function in PHP -- it
will take a delimited string and turn it into an array.

<http://www.php.net/explode>
zeldorblat [ Mo, 16 Juli 2007 02:47 ] [ ID #1770088 ]

Re: Question about reading data I've created with , delimiter

..oO(rebeccatre [at] gmail.com)

>Hello, could someone please show me how to do this.
>
>In a single cell in a DB column, I can have multiple kinds of data
>squeezed together delimited by a comma.
>
>like .....
>"datagreen,datablue,dataorange,datawhite,datayellow,datared ,datablue, ...
>"

You'll run into trouble with such a design. Read about database
normalization (the above violates the first normal form already).

>If I read that data and have it in a string like $datastring...... how
>do I put it into a array situation?

http://php.net/explode

Micha
Michael Fesser [ Mo, 16 Juli 2007 02:49 ] [ ID #1770089 ]

Re: Question about reading data I've created with , delimiter

Usually I get a answer in alt.php concerning MYSQL :-) :-)

I've reposted the question below, I have a very large and complex
environment, and this is just the thing I need to do. Can someone
please show a working example? How does the explode() command help me
pull back #5 data slot? Thank you for your patience and anyone can
help that would be great.


-----------

Hello, could someone please show me how to do this.

In a single cell in a DB column, I can have multiple kinds of data
squeezed together delimited by a comma.

like .....
"datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
"

If I read that data and have it in a string like $datastring...... how
do I put it into a array situation? to access that data.... so if I
want to know what is in spot 5 only, and return back 'datayellow' for
instance, how do I do that? :-) I don't know if array is the right
word, I just want to be able to access any part of that string based
on the order it is in.

Thank you!

Rebecca
rebeccatre [ Mo, 16 Juli 2007 02:57 ] [ ID #1770090 ]

Re: Question about reading data I've created with , delimiter

<?
$string='datagreen,datablue,dataetc';
$ary = explode($string, ',');
foreach($ary as $a)
{
echo "<p>".$a."</p>\t";
}
?>
explode() creates an array by breaking a string on deliminators (boundries).
Running the above in php should output what's below in the client browser.

datagreen
datablue
dataetc

HTH
Vince

<rebeccatre [at] gmail.com> wrote in message
news:1184544785.598523.147040 [at] q75g2000hsh.googlegroups.com.. .
>
>
> Hello, could someone please show me how to do this.
>
> In a single cell in a DB column, I can have multiple kinds of data
> squeezed together delimited by a comma.
>
> like .....
> "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> "
>
> If I read that data and have it in a string like $datastring...... how
> do I put it into a array situation? to access that data.... so if I
> want to know what is in spot 5 only, and return back 'datayellow' for
> instance, how do I do that? :-) I don't know if array is the right
> word, I just want to be able to access any part of that string based
> on the order it is in.
>
> Thank you!
>
> Rebecca
>
Vince Morgan [ Mo, 16 Juli 2007 02:59 ] [ ID #1770091 ]

Re: Question about reading data I've created with , delimiter

..oO(rebeccatre [at] gmail.com)

>Usually I get a answer in alt.php concerning MYSQL :-) :-)
>
>I've reposted the question below, I have a very large and complex
>environment, and this is just the thing I need to do. Can someone
>please show a working example? How does the explode() command help me
>pull back #5 data slot? Thank you for your patience and anyone can
>help that would be great.

Did you actually read the manual page for explode()? Using it is pretty
easy - you feed a string to it and get an array back. The 5th element of
your string would be the 4th element in the array (zero-based indexes).

Micha
Michael Fesser [ Mo, 16 Juli 2007 03:09 ] [ ID #1770094 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> .oO(rebecca... [at] gmail.com)
>
> >Usually I get a answer in alt.php concerning MYSQL :-) :-)
>
> >I've reposted the question below, I have a very large and complex
> >environment, and this is just the thing I need to do. Can someone
> >please show a working example? How does the explode() command help me
> >pull back #5 data slot? Thank you for your patience and anyone can
> >help that would be great.
>
> Did you actually read the manual page for explode()? Using it is pretty
> easy - you feed a string to it and get an array back. The 5th element of
> your string would be the 4th element in the array (zero-based indexes).
>
> Micha

Thank you Micha & Vince, this is kinda the theory that I hope to
figure out. I do understand there is a explode command, but there
isn't sufficient examples out there (or at least I have not found one
yet) related to answer what I would like.

The code example kindly posted by Vince is helpful to understand-see
the explode() command unravel the string, but it doesn't solve the
question I proposed. :( I want to be able to only print part of that
string on demand (5th slot for example).... am I getting close? ;)
rebeccatre [ Mo, 16 Juli 2007 03:15 ] [ ID #1770095 ]

Re: Question about reading data I've created with , delimiter

<?
$string='datagreen,datablue,dataetc';
$ary = explode($string, ',');
echo "<p>".$ary[2]."</p>\t";

?>
Should output:

dataetc

HTH
Vince
<rebeccatre [at] gmail.com> wrote in message
news:1184548548.346329.169130 [at] r34g2000hsd.googlegroups.com.. .
> On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> > .oO(rebecca... [at] gmail.com)
> >
> > >Usually I get a answer in alt.php concerning MYSQL :-) :-)
> >
> > >I've reposted the question below, I have a very large and complex
> > >environment, and this is just the thing I need to do. Can someone
> > >please show a working example? How does the explode() command help me
> > >pull back #5 data slot? Thank you for your patience and anyone can
> > >help that would be great.
> >
> > Did you actually read the manual page for explode()? Using it is pretty
> > easy - you feed a string to it and get an array back. The 5th element of
> > your string would be the 4th element in the array (zero-based indexes).
> >
> > Micha
>
> Thank you Micha & Vince, this is kinda the theory that I hope to
> figure out. I do understand there is a explode command, but there
> isn't sufficient examples out there (or at least I have not found one
> yet) related to answer what I would like.
>
> The code example kindly posted by Vince is helpful to understand-see
> the explode() command unravel the string, but it doesn't solve the
> question I proposed. :( I want to be able to only print part of that
> string on demand (5th slot for example).... am I getting close? ;)
>
Vince Morgan [ Mo, 16 Juli 2007 03:29 ] [ ID #1770096 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:29 pm, "Vince Morgan" <vinharAtHereoptusnet.com.au>
wrote:
> <?
> $string='datagreen,datablue,dataetc';
> $ary = explode($string, ',');
> echo "<p>".$ary[2]."</p>\t";
>
> ?>
> Should output:
>
> dataetc
>
> HTH


Zweet Vince --- you are the best
rebeccatre [ Mo, 16 Juli 2007 03:31 ] [ ID #1770097 ]

Re: Question about reading data I've created with , delimiter

..oO(rebeccatre [at] gmail.com)

>The code example kindly posted by Vince is helpful to understand-see
>the explode() command unravel the string, but it doesn't solve the
>question I proposed. :( I want to be able to only print part of that
>string on demand (5th slot for example).... am I getting close? ;)

No offense intended, but could it be that you're lacking some very
basics like how to access array elements or to print something out?

Micha
Michael Fesser [ Mo, 16 Juli 2007 03:43 ] [ ID #1770098 ]

Re: Question about reading data I've created with , delimiter

On Jul 15, 8:29 pm, "Vince Morgan" <vinharAtHereoptusnet.com.au>
wrote:
> <?
> $string='datagreen,datablue,dataetc';
> $ary = explode($string, ',');
> echo "<p>".$ary[2]."</p>\t";
>
> ?>
> Should output:
>
> dataetc
>
> HTH
> Vince<rebecca... [at] gmail.com> wrote in message
>
> news:1184548548.346329.169130 [at] r34g2000hsd.googlegroups.com.. .
>
> > On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> > > .oO(rebecca... [at] gmail.com)
>
> > > >Usually I get a answer in alt.php concerning MYSQL :-) :-)
>
> > > >I've reposted the question below, I have a very large and complex
> > > >environment, and this is just the thing I need to do. Can someone
> > > >please show a working example? How does the explode() command help me
> > > >pull back #5 data slot? Thank you for your patience and anyone can
> > > >help that would be great.
>
> > > Did you actually read the manual page for explode()? Using it is pretty
> > > easy - you feed a string to it and get an array back. The 5th element of
> > > your string would be the 4th element in the array (zero-based indexes).
>
> > > Micha
>
> > Thank you Micha & Vince, this is kinda the theory that I hope to
> > figure out. I do understand there is a explode command, but there
> > isn't sufficient examples out there (or at least I have not found one
> > yet) related to answer what I would like.
>
> > The code example kindly posted by Vince is helpful to understand-see
> > the explode() command unravel the string, but it doesn't solve the
> > question I proposed. :( I want to be able to only print part of that
> > string on demand (5th slot for example).... am I getting close? ;)

Vince, maybe I missed something in running this, but I actually got a
empty return :(
rebeccatre [ Mo, 16 Juli 2007 03:45 ] [ ID #1770100 ]

Re: Question about reading data I've created with , delimiter

Sorry Rebecca. I should have looked more closely. The parameters for
'explode()' are reversed.
$ary = explode($string, ','); should be as below.
$ary = explode(',', $string);

My appologies,
Vince

<rebeccatre [at] gmail.com> wrote in message
news:1184550344.620682.189780 [at] o61g2000hsh.googlegroups.com.. .
> On Jul 15, 8:29 pm, "Vince Morgan" <vinharAtHereoptusnet.com.au>
> wrote:
> > <?
> > $string='datagreen,datablue,dataetc';
> > $ary = explode($string, ',');
> > echo "<p>".$ary[2]."</p>\t";
> >
> > ?>
> > Should output:
> >
> > dataetc
> >
> > HTH
> > Vince<rebecca... [at] gmail.com> wrote in message
> >
> > news:1184548548.346329.169130 [at] r34g2000hsd.googlegroups.com.. .
> >
> > > On Jul 15, 8:09 pm, Michael Fesser <neti... [at] gmx.de> wrote:
> > > > .oO(rebecca... [at] gmail.com)
> >
> > > > >Usually I get a answer in alt.php concerning MYSQL :-) :-)
> >
> > > > >I've reposted the question below, I have a very large and complex
> > > > >environment, and this is just the thing I need to do. Can someone
> > > > >please show a working example? How does the explode() command help
me
> > > > >pull back #5 data slot? Thank you for your patience and anyone can
> > > > >help that would be great.
> >
> > > > Did you actually read the manual page for explode()? Using it is
pretty
> > > > easy - you feed a string to it and get an array back. The 5th
element of
> > > > your string would be the 4th element in the array (zero-based
indexes).
> >
> > > > Micha
> >
> > > Thank you Micha & Vince, this is kinda the theory that I hope to
> > > figure out. I do understand there is a explode command, but there
> > > isn't sufficient examples out there (or at least I have not found one
> > > yet) related to answer what I would like.
> >
> > > The code example kindly posted by Vince is helpful to understand-see
> > > the explode() command unravel the string, but it doesn't solve the
> > > question I proposed. :( I want to be able to only print part of that
> > > string on demand (5th slot for example).... am I getting close? ;)
>
> Vince, maybe I missed something in running this, but I actually got a
> empty return :(
>
Vince Morgan [ Mo, 16 Juli 2007 03:52 ] [ ID #1770101 ]

Re: Question about reading data I've created with , delimiter

In our last episode,
<1184544785.598523.147040 [at] q75g2000hsh.googlegroups.com>,
the lovely and talented rebeccatre [at] gmail.com
broadcast on comp.lang.php:



> Hello, could someone please show me how to do this.

> In a single cell in a DB column, I can have multiple kinds of data
> squeezed together delimited by a comma.

> like .....
> "datagreen,datablue,dataorange,datawhite,datayellow,datared, datablue, ...
> "

Yes, you could do the same thing with a file-based data system. The point
of using a database is to avoid this sort of thing.

> If I read that data and have it in a string like $datastring...... how
> do I put it into a array situation? to access that data.... so if I
> want to know what is in spot 5 only, and return back 'datayellow' for
> instance, how do I do that? :-) I don't know if array is the right
> word, I just want to be able to access any part of that string based
> on the order it is in.

The best stituation would have been to set up your database properly
(1 cell = 1 datum). As it is, you can use explode on the string which
gives you a one-dimensional array, and the 5th item on the list will
have index 4 in the array (because indices start at 0).

> Thank you!

> Rebecca

--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 554 days to go.
Owing to massive spam from googlegroups, I do not see most posts from there.
Lars Eighner [ Mo, 16 Juli 2007 08:23 ] [ ID #1770110 ]
PHP » alt.php » Question about reading data I've created with , delimiter

Vorheriges Thema: session_set_save_handler and error handling
Nächstes Thema: Race condition when inserting data / MySQL 4.0+, MyISAM tables