Jump to content

dropdown list ( select ) behaving very wierd


senso321

Recommended Posts

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 :o

<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 by senso321 (see edit history)
Link to comment
Share on other sites

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 by senso321 (see edit history)
Link to comment
Share on other sites

  • 3 years later...

   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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...