Closed Thread Icon

Topic awaiting preservation: mysql and/or php question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24681" title="Pages that link to Topic awaiting preservation: mysql and/or php question (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: mysql and/or php question <span class="small">(Page 1 of 1)</span>\

 
DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-13-2005 16:30

Hopefully an easy question -

I have a field in a mysql db in which 2 items will be stored (always 2 - never more or less), seperated by a comma.

How can I get the values of the item before and after the comma as seperate variables?

I'm sure this type of thing is done all the time, but I've enver had to do such things...not sure what to look at.

Any tips appreciated.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 01-13-2005 16:35

On the PHP side you could simplyexpode() the string. On the SQL side you'll certainly have to this by hand, that is you'll have to stuff your query with some string manipulation to find the position of the coma and split the value of the field in two accordingly.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 01-13-2005 17:16

though you really should have two seperat fields in this case.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-13-2005 17:42

well, in most cases, I'll use it as it is stored - with the comma.

In some cases, i want to be able to split them.

thought if there were an easy way, it might be simpler to keep them stored together...

{edit -

looks like explode is what I was looking for - thanks poi.

this is also for learning purposes as much as it is for practical application - I've never dealt with this type of thing, so it's something I want to play around with.



(Edited by DL-44 on 01-13-2005 17:48)

crip
Bipolar (III) Inmate

From: iasi, romania
Insane since: Apr 2002

posted posted 01-13-2005 23:26

Was google or php.net down the day you asked this?
I'm sure I'm gonna be the bad guy on this, blah-blah, but i just can't forget the many times DL-44 was a bit too drastic on help requests
I'm not doing it of spite, as it never happened to me , as i said, i just could't help remembering. I promose not to flame, even if i get called an idiot


Curiously yours, crip

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-13-2005 23:47

no, in fact it wasn't.

As I said, I haven't dealt with thia kind of problem, thus did not know what I was looking for, and so the searches I did were unproductive.

But gee, thanks for asking...

(and for the record, none of my so called "drastic" repsonses have been so devoid of content as ^that. they ahve had a point that unfortunately many people take as "drastic" or even rude. but that does not in any way invalidate the points that I generally made in such responses...)

I X I
Paranoid (IV) Inmate

From: beyond the gray sky
Insane since: Apr 2004

posted posted 01-14-2005 08:15

[venting]
I find that the hardest questions to find answers for are the ones you're not quite sure how to ask. I can understand why some people ask what others may think are silly questions, such as the thread that popped up not too long ago about "cutting up an image into smaller pieces." if you don't know exactly what to search for then it is alot harder to find answers on your own.
[/venting]

I personally wouldn't have known to look for explode() in php, as I'm native to VB I would have expected to look for left, mid or instr.

just my .02,



Do you serve a purpose or purposely serve (Corey Taylor)

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 01-14-2005 09:30

It is difficult sometimes to find information on something when you don't know exactly what you're looking for. Search engines are great, but they're not human beings. For example, if you tried to ask Google "How do I split a string into separate variables with PHP?" you would get a great big "Huh?"

Just yesterday, for example, I was trying to figure out how to get line breaks into my PHP code. I ended up typing "line breaks" and "php" into Google and sifting through the results. It took me forever to come up with a phrasing that was neither too wide nor too narrow, though.

The problematic posts (and subsequent responses) are those in which the person has apparently put in no effort beforehand and is just looking for a quick fix to a major issue, rather than help on a specific technique.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup | "Hooray for linguistic idiots and yak milk!"

(Edited by Suho1004 on 01-14-2005 09:31)

« BackwardsOnwards »

Show Forum Drop Down Menu