Jump to content


multiply two fields

multiply fields

  • Please log in to reply
5 replies to this topic

#1 MD Rahat Islam Khan

MD Rahat Islam Khan

    Member

  • Members
  • PipPip
  • 13 posts

Posted 18 February 2014 - 05:09 PM

i am very new to grocery crud and i am getting fond of it.now i want to know a thing:

i have two column "quantity" and "price" in the database and want to show the total by quantity*price to another field."total" in crud

 

so my table field will be "quantity","price","total".it will be very helpful if some one help my solving this



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 18 February 2014 - 09:10 PM

well u can use callback_column function to customize your display for total column.



#3 Robert

Robert

    Advanced Member

  • Members
  • PipPipPip
  • 220 posts

Posted 20 February 2014 - 07:12 AM

Here is a small example to get you started

 

In the controller : 

$crud->callback_column('total', array($this,'_total')); // add total to display columns

now the callback function :

public function _total($value, $row) {
      return "$row->quantity x $row->price";
}


#4 jcanongia

jcanongia

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 07 July 2016 - 09:33 PM

I have this controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		$this->load->database();
		$this->load->library(array('ion_auth','form_validation'));
		$this->load->helper(array('url','language','form'));
		$this->load->library('grocery_CRUD');

		$this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));

		$this->lang->load('auth');

	}

	public function index()
	{
		if (!$this->ion_auth->is_admin())
		{
			$this->session->set_flashdata('message', '<div class="alert alert-info" role="alert">You must be an admin to view this page</div>');
			redirect('/');
		}
		$crud = new grocery_CRUD();
		$crud->set_table('personals');
		$crud->set_subject('Pessoas');
		$crud->columns('nome','data_nascimento','nome_mae','nome_pai','estado_civil','sexo','regime_estado_civil','cpf','rg',
		'data_exp_rg','orgao_exp_rg','ctps_serie','ctps_numero','ci_inss_numero','pis_pasep','country_id','naturalidade_id','user');
		$crud->display_as('data_nascimento','Nascimento')->display_as('nome_mae','Nome Mãe')->display_as('nome_pai','Nome Pai')
		   ->display_as('regime_estado_civil','Reg Casamen')->display_as('data_exp_rg','Expira RG')->display_as('orgao_exp_rg','Orgão RG')
		   ->display_as('country_id','Nacionalidade')->display_as('naturalidade_id','Naturalidade')->display_as('user','Nome Usuar');
		$crud->set_relation('country_id','countries','nome');
		$crud->set_relation('user_id','users','{id}.{username}');
		$crud->callback_column('user', array($this, '_callback_webpage_url'));
		$output = $crud->render();

		$this->_example_output($output);
	}

	public function _callback_webpage_url($value, $row)
	{
		return '<a href="'.base_url("user_view/index/".$row->user_id).'">'.$row->user_id.'</a>';
	}

	function _example_output($output = null)
	   {
			$this->load->view('admin/template/header');
			$this->load->view('admin/dashboard',$output);
			$this->load->view('admin/template/footer');
	   }


}

This let me link users table by id in column user.

 

PrtSc%20Personals.jpg

That you can see in Nome Usuar column. But I need put in that column the username instead the user_id. How can I do that.

 

Sorry my english.



#5 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 12 July 2016 - 07:57 AM

Well  sorry for delay,

 

What i see - you have put is user_id a relation with users table showing in id & username - think -there is the place where u just need to put the username only. That will solve your issue.

 

Other, what i see in here is the columns you chosen to display dose not have the user_id as the field- thats where you might be missing out the same. Just go ahead and add the user_id field in columns and it will start showing the username.



#6 jcanongia

jcanongia

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 20 July 2016 - 12:48 PM

Hi Amit!

I think I have solved that!

The column's name is passed whith md5, only the first 8 elements, plus "s".

Like user_id = s+e8701ad48ba05a91604e480dd60899a3 and  country_id=s+93bfec8a344ef19318d53f3e3b5b9bf0

 

Then I just use

        $crud->callback_column('username', array($this, '_callback_webpage_username'));
public function _callback_webpage_username($value, $row)
    {
        return '<a href="'.base_url("user/view_user/".$row->user_id).'">'.$row->se8701ad4.'</a>';
    }

Then the result is whith username.name and a link.

 

Thank you so much. Regards







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users