Jump to content

array in select query


cocodeluxe

Recommended Posts

Hi and thanks for the support

 

I want to create a variable with the vat number so when a customer has validated vat number will appear a tax free message in his account 
 
I created the variable in FrontController
 
	     $context = Context::getContext();
               
                $customer = $context->customer;
                $id_customer = $customer->id;
				
				$vat_number = Db::getInstance()->executeS("SELECT " ._DB_PREFIX_. "address.vat_number 
				FROM " ._DB_PREFIX_. "address                                
                                WHERE " ._DB_PREFIX_. "address.id_customer = '$id_customer'");
              	$this->context->smarty->assign(array(
	'vat_number' => $vat_number,
	));

Works ok but show an array with 2 results, the number an other empty

Smarty_Variable Object (3)
->value = Array (2)
  0 => Array (1)
    vat_number => ""
  1 => Array (1)
    vat_number => "SE663000019501"
->nocache = false

Why can I do to leave only the number result ?

 

 

 

 

Thanks

Link to comment
Share on other sites

Thanks Pascal

 

Yes two rows in this query

Smarty_Variable Object (3)
->value = Array (2)
  0 => Array (1)
    vat_number => ""
  1 => Array (1)
    vat_number => "SE663000019501"
->nocache = false

one empty and other with the  vat number

 

 

 

How can I text it in the query in this way  ¿?

	     $context = Context::getContext();
               
                $customer = $context->customer;
                $id_customer = $customer->id;
				
				$vat_number = Db::getInstance()->executeS("SELECT " ._DB_PREFIX_. "address.vat_number 
				FROM " ._DB_PREFIX_. "address                                
                                WHERE " ._DB_PREFIX_. "address.id_customer = '$id_customer'
                                AND .vat_number != ""
");
              	$this->context->smarty->assign(array(
	'vat_number' => $vat_number,
	));
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...