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.089 seconds

Hi All just wanted to add one more "thank you" voice to all those who discovered the value of this amazing application. The website I was working on went to production few days ago and I do not want to even try to imagine what would it take to build it without j-cook. So - endless thanks keep it running and evolving I believe it deserves to be the core tool for any joomla application! Thanks!
Michael (bmk028 - Forum)  

Get Started