Hi everyone
I’m a complete newbie in PHP developping, i started like 2 weeks ago, and i have to realize a project.
I won’t say a lot about that project, but i have a problem realizing it.
in my mySQL DB, i have a table that contains a number of item that has been sold, a price, etc.
I would like to make statistics about those lines. So i have a model, controller, view etc for the lines, but it can’t render statistics.
i created thoses classes for my statistics. But i cant succeed to passes the selected parameters…
Here’s my code:
In the controller
public function actionSelectStats(){
$this->renderPartial('selectStats');
}
in my default view:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'autorisation-vente-form',
'enableAjaxValidation'=>false,
)); ?>
<?php
$article = new Article();
$machine = new Machine();
$personne = new Personnes();?>
<div class="row">
<?php echo $form->labelEx($article,'Choix de l\'article'); ?>
<?php
//cette forme ci de dropdownliste permet d'ajouter un élément au début. Du coup, on n'est pas obligé
//de sélectionner un article.?>
<?php echo $form->dropDownList($article,'ID',CHtml::listData(Article::model()->findAll(), 'ID', 'libelle'),array('empty'=>Yii::t('fim','Tous les articles')));?>
<?php echo $form->error($article,'article'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($machine,'Choix de la machine'); ?>
<?php echo $form->dropDownList($machine,'ID', CHtml::listData(Machine::model()->findAll(), 'ID', 'nomMachine'),array('empty'=>Yii::t('fim','Toutes les machines'))); ?>
<?php echo $form->error($machine,'ID'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($personne,'Choix de la personne'); ?>
<?php echo $form->dropDownList($personne,'ID', CHtml::listData(Personnes::model()->findAll(), 'ID', 'prenom', 'nom'),array('empty'=>Yii::t('fim','Tout le monde'))); ?>
<?php echo $form->error($personne,'ID'); ?>
</div>
<?php echo "<input type=\"button\" value=\"valider\" onclick=\"showStats()\">" ;?>
</div>
<?php $this->endWidget(); ?>
my javascript:
function showStats(){
if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4){
document.getElementById("donnees").innerHTML=xmlhttp.responseText;
}else{
}
}
xmlhttp.open("GET","selectStats",true);
xmlhttp.send();
}
and the selectStats.php works fine, nothing to see there.
So, i know that this code won’t ever passes the needed parameters. But i already tried everything, and i can’t figure out how to do that. I don’t even know if i’m following a good path.
Right now the only think i succeed to do is listing ALL the lines of my DB on my view. Ho yeah, in my view if i do:
<?php echo "<input type=\"button\" value=\"valider\" onclick=\"showStats($var1, $var2, $var3)\">" ;?>
the $var* are evaluated when the page is loaded and that won’t work. I did not figure out how to retrieve the parameters from my form?
Can anyone help me?
PS: sorry for my poor english, that’s not my mother language