Jump to content

Explode it inside a query?


Monkuar

Recommended Posts

Here is my query

SELECT id,username,star,color,actions from users WHERE actions >= 1 ORDER BY actions DESC

 

actions field value is "213|1336456267"

 

how can I use mysql to explode so it only reads the first literation of the exploded values, like 213?

 

Is this why people always say you shouldn't store exploded variables? :P

 

Theres gotta be a way tho right?

 

in other words; is there a mysql function that exploded that actions variable in the query with a | to read only the "213" ?

 

 

Link to comment
Share on other sites

 

I dont understand the syntax

mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
        -> 'www.mysql'

 

is www.mysql.com supposed to represent the field name or?

 

 

so something like this:

 

SELECT SUBSTRING_INDEX('actions', '|', 2);

 

?

Link to comment
Share on other sites

$db->query('SELECT id,username,star,color,actions from users WHERE actions >= 1 ORDER BY SUBSTRING_INDEX(\'actions\', \'|\', 2) DESC')

 

WOW

 

TOPIC SOLVED!!!

 

Didn't know you could do this, wow I can store alot of information in explodes now and call them.

 

AwesomE!

Link to comment
Share on other sites

You should only store information in explodes (delimited information) when you don't want to query specific values in that data. You're greatly slowing down your query by using SUBSTRING_INDEX

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.