Jump to content
MakeWebGames

Selecting a specific value within a field?


UOTS-Owner

Recommended Posts

6 minutes ago, UOTS-Owner said:

Anyone know how to select a certain value in this field? For instance the 6th one in which shows as 1

https://ibb.co/wzTtxKG

This is the current setup but it just selects the first number every time.

 

SELECT `usr_id`,SUBSTRING_INDEX(usr_stat,':',6) AS offences
        FROM `usr_tbl` 
        ORDER BY `offences` DESC 
        LIMIT 25

Store the results in an array and recall it using an array key

Link to comment
Share on other sites

12 hours ago, KyleMassacre said:

I would have personally serialized it but I guess you could explode it and get the index number you want 

Could I get an example please to work off say for replacing the original one?

 

SELECT `usr_id`,SUBSTRING_INDEX(usr_stat,':',6) AS offences
        FROM `usr_tbl` 
        ORDER BY `offences` DESC 
        LIMIT 25

Link to comment
Share on other sites

$query = $mysql->query("SELECT `usr_id`, `usr_stat` AS offenses
        FROM `usr_tbl` 
        ORDER BY `offenses` DESC 
        LIMIT 25");
$result = $mysql->fetch($query);

$offenses = explode($result['offenses]);

print $offenses[6];

You can't really do what you want to do in MySQL unless you create a function and I don't know if that is possible for everyone to do depending on your hosting.

But if it is something you would want to look into you can look here

Link to comment
Share on other sites

  • 2 years later...
  • 1 month later...

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.   Paste as plain text instead

  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...