Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

récupérer le id d'un enregistrement 09 Dec 2012 13:32 #5945

  • LJ01
  • LJ01's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
bonjour
dans un model de vue item
j'exécute cette fucniton
      	function conso()
	  {    	                                    
	  $user = JFactory::getUser();
	  $userid = $user->id;

	  $params = JComponentHelper::getParams('com_batenergie');
	  $kwhx_fioul = $params->get('kwhx_fioul', 1);
	  $kwhx_gas = $params->get('kwhx_gas', 1);
	  $kwhx_gasp = $params->get('kwhx_gasp', 1);
	  $kwhx_elec = $params->get('kwhx_elec', 1);
	  $kwhx_boisp = $params->get('kwhx_boisp', 1);
	  $kwhx_boisg = $params->get('kwhx_boisg', 1);
	  $kwhx_boisb = $params->get('kwhx_boisb', 1);
		                       
		$database =& JFactory::getDBO()  ;
	 	$database->setQuery( "SELECT SUM(dpe09_fioul * $kwhx_fioul)
						+ (dpe09_gas * $kwhx_gas)
						+ (dpe09_gasp * $kwhx_gasp)
						+ (dpe09_elec * $kwhx_elec)
						+ (dpe09_boisp * $kwhx_boisp)
						+ (dpe09_boisg * $kwhx_boisg)
						+ (dpe09_boisb * $kwhx_boisb)
					FROM #__batenergie 
					WHERE author='$userid' 
					AND id='$bat'
					" );
		if (!$database->query()) {
		    echo $database->stderr();
		    return false;
		}

	  return $database->loadResult();
	  }

la requête sql s'exécute sur toute la base, je souhaite la restreindre à l'item sélectionné avec AND id='$bat'
mais comment définir $bat qui sera l'id de mon item?
LJ
Ce sont les fils qui font les cordes
ingall-niger.org

Please Log in or Create an account to join the conversation.

Last edit: by LJ01.

Re: récupérer le id d'un enregistrement 21 Dec 2012 10:11 #6216

  • LJ01
  • LJ01's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 78
  • Thank you received: 2
j'ai testé
$batid = $this->_id;
$batid = $item->_id;
$batid = $this->_data->id;
$batid = $item->_data->_id;
$batid = $data->_id;

sans suite ...
Ce sont les fils qui font les cordes
ingall-niger.org

Please Log in or Create an account to join the conversation.

Re: récupérer le id d'un enregistrement 25 Jan 2013 10:31 #6503

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
A partir du controller, l'id n'est pas encore décodé, donc il faut aller le chercher dans la requete (JInput).

Si vous écrivez cela dans le modèle il y a des facilités et l'ID se trouve dans $model->getState('xxxx.id')
xxxx est le nom de la vue.
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.110 seconds

Amazing Tool !
And only tool I know that allows complete Scaffolding in terms of component creation. It really saves loads of time (actually much more than that). Simple architecture enables quick and painless changes at any time. Code is clean and consintent. It's just... what's the word... neat! :) Great work! You should definetely try this one!

pi_wo (JED)
         

Get Started