UOTS-Owner Posted May 8, 2021 Share Posted May 8, 2021 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 Quote Link to comment Share on other sites More sharing options...
Spydre452 Posted May 8, 2021 Share Posted May 8, 2021 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 Quote Link to comment Share on other sites More sharing options...
UOTS-Owner Posted May 8, 2021 Author Share Posted May 8, 2021 4 minutes ago, Spydre452 said: Store the results in an array and recall it using an array key Yeah this is in here but I dont know how to select it https://ibb.co/P5gJFGp Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 8, 2021 Share Posted May 8, 2021 I would have personally serialized it but I guess you could explode it and get the index number you want Quote Link to comment Share on other sites More sharing options...
UOTS-Owner Posted May 9, 2021 Author Share Posted May 9, 2021 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 Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 9, 2021 Share Posted May 9, 2021 $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 Quote Link to comment Share on other sites More sharing options...
Maz Posted October 4 Share Posted October 4 (edited) If all the number values are from 0 to 9, this is valid: SELECT usr_id, SUBSTRING(usr_stat, 11, 1) AS offences FROM `usr_tbl` ORDER BY `offences` DESC LIMIT 25; Edited October 4 by Maz Quote Link to comment Share on other sites More sharing options...
smith Posted November 20 Share Posted November 20 ?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.