Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 464 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating MySQL query with MyBB to explode a field storing a string

#1
I am currently working with a MyBB set up where I am trying to do an SQL query which can check if a user is part of a certain additional group. However, I am having difficulties.

MyBB stores additional group IDs in one VARCHAR field separated by commas, such as 1,23,27,30,49 etc. I know that in PHP I can explode strings using the comma as a delimiter. I understand that MySQL cannot explode, but I can use substring_index to achieve a similar goal. Point to note each user could have a random list of additional groups, so not all users would be the same.

I am trying this

$stmt = $conn->query('SELECT username, additionalgroups FROM my_users WHERE SUBSTRING_INDEX(30, ',', 1)');
foreach ($stmt as $row)
{
print '<div class="name"><a href="#">' . $row['username'] . '</a></div>';
}


This does not seem to work though. Looking at

[To see links please register here]

I seem to be following their way of constructing the condition, but I get the following error:

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: mode must be an integer in E:\xampp\htdocs\11thinfantrybrigade.co.uk\orbat.php:180 Stack trace: #0 E:\xampp\htdocs\11thinfantrybrigade.co.uk\orbat.php(180): PDO->query('SELECT username...', ', 1)') #1 {main} thrown in E:\xampp\htdocs\11thinfantrybrigade.co.uk\orbat.php on line 180

Any advice please?

The end goal is to print a list of users that meet that criteria.

Thank you.
Reply

#2
$stmt = $conn->query('SELECT username, additionalgroups FROM my_users WHERE SUBSTRING_INDEX(\'30\', \',\', 1)');

Preferably it should be like this as the `,` outside the quotes will cause trouble to PHP.
Reply

#3
$query = 'SELECT username FROM my_users WHERE CONCAT(",",additionalgroups,",") LIKE "%,30,%"' ;

$stmt = $conn->query($query);
foreach ($stmt as $row)
{
print '<div class="name"><a href="#">' . $row['username'] . '</a></div>';
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through