senso321 Posted January 14, 2014 Share Posted January 14, 2014 (edited) Hello all, im working on a module and I ran into a wierd problem. While trying to populate a dropdown select list from mySQL database. Smarty somehow forces my list to have optgroups and I cant figure out why. Here is my code Module: $sql_select = 'SELECT `name` FROM `'._DB_PREFIX_.'projekt`'; $result=Db::getInstance()->ExecuteS($sql_select); $this->context->smarty->assign('myOptions', array($result)); And front end {html_options name=test options=$myOptions} But somehow my outcome looks like this <select name="test"> <optgroup label="0"> </optgroup> <optgroup label="0"> <option value="name">test_projekt</option> </optgroup> <optgroup label="1"> <option value="name">Projekti test</option> </optgroup> </select> Can anyone help me? Prestashops documention sucks. Smarty's is a little better but still it's as bad as prestashops. BR's. Edited January 14, 2014 by senso321 (see edit history) Link to comment Share on other sites More sharing options...
senso321 Posted January 14, 2014 Author Share Posted January 14, 2014 (edited) Okay basicly the problem was, that if you require information from database via command executeS then it creates a multilingual array ( arrays within one array ) which is very bad because you cant transplant it to smarty directly. here is my solution to work around the problem: $values_sql = 'SELECT id FROM `'._DB_PREFIX_.'projekt`'; $multi_array_values = Db::getInstance()->ExecuteS($values_sql); $values_array = array(); foreach ($multi_array_values AS $key => $value) { $values_array[] = $value['id']; } And then to transplant it to a simpel smarty array I jus tused this $this->context->smarty->assign('values', $values_array); let's hope that this topic will be useful for someone in the future BR's Edited January 15, 2014 by senso321 (see edit history) Link to comment Share on other sites More sharing options...
bhu24 Posted June 2, 2017 Share Posted June 2, 2017 hey i am having problem in one module i am new in prestashop but i have to make one module where you can search invoice by order id and i didnt get order id in drop down .please let me know how to do this . Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now