Mysql issue with – character

QuestionsMysql issue with – character
Cedric asked 6 years ago

Hello, I am facing an issue with creating Select with a column name that contains a – character

$sqldpt=”select distinct ‘$site’ as k, ‘$site’ as v from si_dptlist”;
# on change, update other dropdown
$str = $g->get_dropdown_values($sqldpt);
$col[“editoptions”] = array(“value”=>$str);
// load from query on every edit mode
$col[“editoptions”][“onload”][“sql”] = $sqldpt;

the tables contains 3 columns

Voreppe, Brzeg-Dolny,Wesseling

Only issue with column Brzeg-Dolny

If i use this:
$sqldpt=”select distinct ‘$site’ as k, ‘$site’ as v from si_dptlist”;
it works but the select is filled only with Brzeg-Dolny

If I use:
$sqldpt=”select distinct $site as k, $site as v from si_dptlist”;
I get this error:
Couldn’t execute query. Unknown column ‘Brzeg’ in ‘field list’ – select distinct Brzeg-Dolny as k, Brzeg-Dolny as v from si_dptlist

I need some help to get around this issue..

Thanks,

Cedric

 

2 Answers
Abu Ghufran Staff answered 6 years ago

Hello,

If you are using mysql, then you should use ` sign around column names.
$sqldpt=”select distinct `$site` as k, `$site` as v from si_dptlist”;

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
cedric answered 6 years ago

feeling dumb now…

Thanks

Your Answer

13 + 20 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?