PDA

View Full Version : WHERE Clause


Benumbed
07-21-2005, 06:08 AM
If I do...

$loadedmodulename = $loadedmodule[module];





$settings = $DB_site->query("
SELECT setting.*, settinggroup.*
FROM " . TABLE_PREFIX . "dwip_module_settinggroup AS settinggroup
LEFT JOIN " . TABLE_PREFIX . "dwip_module_setting AS setting USING(grouptitle)
WHERE settinggroup.module = $loadedmodulename
");


I get


Database error in vBulletin 3.0.7:

Invalid SQL:
SELECT setting.*, settinggroup.*
FROM dwip_module_settinggroup AS settinggroup
LEFT JOIN dwip_module_setting AS setting USING(grouptitle)
WHERE settinggroup.module = sitenav


mysql error: Unknown column 'sitenav' in 'where clause'


but if I manually put

WHERE settinggroup.module = 'sitenav'

it works fine.

Its as though its not passing the variable right or I am calling it wrong within the WHERE. I have tried different ways but cant seem to get it.

Adrian Schneider
07-21-2005, 06:12 AM
try
WHERE settinggroup.module='$loadedmodulename'

Benumbed
07-21-2005, 06:25 AM
I had tried that before...

Warning: Invalid argument supplied for foreach() in /admincp/dwip_modules.php on line 834


This is that line


foreach ($grouptitlecache AS $curgroup => $group)
{
print_dwipsetting_group($curgroup, $advanced);
print_description_row("<input type=\"submit\" class=\"button\" value=\" $vbphrase[save] \" tabindex=\"1\" title=\"" . $vbphrase['save_settings'] . "\" />", 0, 2, 'tfoot" style="padding:1px" align="right');
print_table_break(' ');
}


What is weird is that if I dont do '$loadedmodulename' and do 'sitenav' (which is one of the variables), it works fine. I cant understand why if I manually do it in script, it works but as a variable, it doesnt. I cant just do 'sitenav" either as there is like 20 different variables on what I am trying to seperate.

Marco van Herwaarden
07-21-2005, 06:45 AM
WHERE settinggroup.module='" . addslashes($loadedmodulename) . "'
Try the above line instead, sounds to me like you have a modulename with a quote in it or another special character.

Benumbed
07-21-2005, 06:49 AM
same thing =\

I really dont understand why it doesnt work.

Explain (its in debug mode trying to fix this) of it with $ variable

Query:

SELECT setting.*, settinggroup.*
FROM dwip_module_settinggroup AS settinggroup
LEFT JOIN dwip_module_setting AS setting USING(grouptitle)
WHERE settinggroup.module=''

Time before: 0.090831995010376
Time after: 0.091269016265869
Time taken: 0.00043702125549316

table type possible_keys key key_len ref rows Extra
settinggroup ALL 3 Using where
setting ALL 3



Explain if I just set it a constant (sitenav)


Query:

SELECT setting.*, settinggroup.*
FROM dwip_module_settinggroup AS settinggroup
LEFT JOIN dwip_module_setting AS setting USING(grouptitle)
WHERE settinggroup.module='sitenav'

Time before: 0.12685608863831
Time after: 0.12722706794739
Time taken: 0.00037097930908203

table type possible_keys key key_len ref rows Extra
settinggroup ALL 3 Using where
setting ALL 3

Marco van Herwaarden
07-21-2005, 07:02 AM
Query:

SELECT setting.*, settinggroup.*
FROM dwip_module_settinggroup AS settinggroup
LEFT JOIN dwip_module_setting AS setting USING(grouptitle)
WHERE settinggroup.module=''
By the looks of it, the $loadedmodulename variable is empty.

Benumbed
07-21-2005, 07:08 AM
Its not, that was the explain after I hit "Edit Setting"

Before Explain is this...



Query:

SELECT setting.*, settinggroup.*
FROM dwip_module_settinggroup AS settinggroup
LEFT JOIN dwip_module_setting AS setting USING(grouptitle)
WHERE settinggroup.module='sitenav'

Time before: 0.31128311157227
Time after: 0.31180191040039
Time taken: 0.000518798828125

table type possible_keys key key_len ref rows Extra
settinggroup ALL 3 Using where
setting ALL 3



What this basically is, is the vBulletin Options call (to edit your settings) modified to do some other options of a portal like thing I am trying to make. Somewhere between me seeing the options and then clicking on Show all setting, its like its losing the variable if I have it a variable and not a constant.

After typing my last response, I gotta hint and sure enough.. I forgot my hiddencode tags...thanks =P