MyBB Community Forums

Full Version: 1 sql question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im probably just blind but does anyone see anything wrong with this code?? It wont work.
SELECT `gid` FROM `".TABLE_PREFIX."settinggroups` WHERE `name` = `Rules`
It is supposed to get the gid value of a group called Rules in the names table for another sql query later on. But when I execute the code in phpMyAdmin I get this error:
Quote: MySQL said: Documentation
#1054 - Unknown column 'Rules' in 'where clause'
Simple answer or link please, still learning.

And yes, I have double, and even triple checked that Rules is in the name column located in ".TABLE_PREFIX."settinggroups ( mybb_settinggroups )
You're using those funny ` things the value, meaning it thinks it is a field.

Use:

SELECT gid FROM ".TABLE_PREFIX."settinggroups WHERE name='Rules';

It should work.
ok, that works fine, now how do I include that result in another sql command cause it doesn't seem to work (not supprised though)
// Setting: Rules
$sql = "SELECT gid FROM ".TABLE_PREFIX."settinggroups WHERE name='Rules'";
$gid = $db->query($sql);
$sql = "INSERT INTO `".TABLE_PREFIX."settings` (`sid`,`name`,`title`,`description`,`optionscode`,`value`,`disporder`,`gid`) VALUES ('','rules_list','Rules List','This is where you can specify what rules are to display on rules.php.','textarea','Enter your rules in here.','1','$gid');";
$query = $db->query($sql);
Any ideas how I could do that, if its posible??
You need to actually fetch a row from the results, under $gid = $db->query($sql); add $gid = $db->fetch_array($gid);
added it, but still no effect. It turns out as 0, everything I try does that. My guess would be it isn't getting the value's from the DB. But whats weird is if I run the query in phpMyAdmin, it gets the right value it should. This is the current code I'm using:
// Setting: Rules
$sql = "SELECT gid FROM ".TABLE_PREFIX."settinggroups WHERE name='Rules'";
$query = $db->query($sql);
$gid = $db->fetch_array($query);
$sql = "INSERT INTO `".TABLE_PREFIX."settings` (`sid`,`name`,`title`,`description`,`optionscode`,`value`,`disporder`,`gid`) VALUES ('','rules_list','Rules List','This is where you can specify what rules are to display on rules.php.','textarea','Enter your rules in here.','1','$gid');";
$query = $db->query($sql);
I, being new to this type db selection, see nothing wrong with it. It looks like it would do what I want it to but it doesn't Sad Can you see anything wrong with it??
$gid will be an array of $gid['gid'];

mysql_fetch_array (or $db->fetch_array in MyBB) returns an array of the selected fields.
thanks so much both of you. Helped heaps. Next version of the rules mod coming out very soon Smile