Custom SQL duplicate column names. WHERE clause not working

QuestionsCustom SQL duplicate column names. WHERE clause not working
Vygandas Pigaga asked 6 years ago

Hello,

I have to use custom SQL:

$g->select_command = “SELECT gaminiai.id as id, gaminiai.code as gaminiai_code, gaminiai.name as gaminiai_name, gaminiai.ean as gaminiai_ean, gaminiai.ar_batt_charger as gaminiai_ar_batt_charger, battery.code as battery_code, charger.code as charger_code
FROM gaminiai
LEFT JOIN battery on battery.id = gaminiai.battery_id
LEFT JOIN charger on charger.id = gaminiai.charger_id”;

Displays fine!
But if I use Search, I get error, because MySQL does not allow to use Alias in Where Clause:

Couldn’t execute query. Unknown column ‘gaminiai_code’ in ‘where clause’ – SELECT count(*) as c FROM (SELECT gaminiai.id as id, gaminiai.code as gaminiai_code, gaminiai.name as gaminiai_name, gaminiai.ean as gaminiai_ean, gaminiai.ar_batt_charger as gaminiai_ar_batt_charger, battery.code as battery_code, charger.code as charger_code FROM gaminiai LEFT JOIN battery on battery.id = gaminiai.battery_id LEFT JOIN charger on charger.id = gaminiai.charger_id WHERE 1=1 AND ( `gaminiai_code` LIKE ‘%178%’ )) pg_tmp

2 Answers
Vygandas answered 6 years ago

UPDATE:

Solved. SImply change returned id’s to names/varchar with this:

$col[“dbname”] = “gaminiai.battery_id”;
$col[“editoptions”] = array(“table”=>”battery”, “id”=>”id”, “label”=>”code”);

The only thing left unclear – is how to export XLS value, not id….

Abu Ghufran Staff answered 5 years ago

Just to log an update, fix for excel export for dropdown is supported in latest build now.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

4 + 6 =

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 0 / 5. Vote count: 0

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?