paskuale
(Pellicanipasquale)
September 8, 2012, 11:25am
1
Ciao stò andando in corto avrei un array formato da [anno],[mese],[giorno] che devo stampare in questa maniera:
nell’anno X del mese Y ha questi app.ti : giorno1; giorno2; gioro4; etc…
nell’anno Xx del mese Yy ha questi app.ti : giorno5; giorno21; gioro7; etc…
nell’anno Xxx del mese Yyy ha questi app.ti : giorno11; giorno14; gioro15; etc…
stò rincretinendo dietro ad una serie di condizioni (if then …) ma non ne esco !!!
qualche consiglio ?
thnks
p.s.
allego var_dump della queryAll()
array(18) { [0]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "18" } [1]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "19" } [2]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "20" } [3]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "23" } [4]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "25" } [5]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "27" } [6]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "30" } [7]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "2" } [8]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "3" } [9]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "6" } [10]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "8" } [11]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "10" } [12]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "20" } [13]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "22" } [14]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "24" } [15]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "27" } [16]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "29" } [17]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "31" } }
sensorario
(Sensorario)
September 8, 2012, 11:30am
2
paskuale:
Ciao stò andando in corto avrei un array formato da [anno],[mese],[giorno] che devo stampare in questa maniera:
nell’anno X del mese Y ha questi app.ti : giorno1; giorno2; gioro4; etc…
nell’anno Xx del mese Yy ha questi app.ti : giorno5; giorno21; gioro7; etc…
nell’anno Xxx del mese Yyy ha questi app.ti : giorno11; giorno14; gioro15; etc…
stò rincretinendo dietro ad una serie di condizioni (if then …) ma non ne esco !!!
qualche consiglio ?
thnks
p.s.
allego var_dump della queryAll()
array(18) { [0]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "18" } [1]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "19" } [2]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "20" } [3]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "23" } [4]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "25" } [5]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "27" } [6]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "7" ["GIORNO"]=> string(2) "30" } [7]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "2" } [8]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "3" } [9]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "6" } [10]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(1) "8" } [11]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "10" } [12]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "20" } [13]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "22" } [14]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "24" } [15]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "27" } [16]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "29" } [17]=> array(3) { ["ANNO"]=> string(4) "2012" ["MESE"]=> string(1) "8" ["GIORNO"]=> string(2) "31" } }
Potresti formattare l’array? Così è illeggibile. Mi mostreresti anche come hai formato l’array? Credo abbia senso formarlo già ordinato così da non doverti complicare la vita dopo in fase di lettura.
paskuale
(Pellicanipasquale)
September 8, 2012, 11:33am
3
array(18) {
[0]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "18"
}
[1]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "19"
}
[2]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "20"
}
[3]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "23"
}
[4]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "25"
}
[5]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "27"
}
[6]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "7"
["GIORNO"]=>
string(2) "30"
}
[7]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(1) "2"
}
[8]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(1) "3"
}
[9]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(1) "6"
}
[10]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(1) "8"
}
[11]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "10"
}
[12]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "20"
}
[13]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "22"
}
[14]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "24"
}
[15]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "27"
}
[16]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "29"
}
[17]=>
array(3) {
["ANNO"]=>
string(4) "2012"
["MESE"]=>
string(1) "8"
["GIORNO"]=>
string(2) "31"
}
}
paskuale
(Pellicanipasquale)
September 8, 2012, 11:36am
4
è frutto di questa query:
SELECT
p1.id, YEAR(trt_data) AS ANNO, MONTH(trt_data) AS MESE, DAY(trt_data)AS GIORNI
FROM tbl_paziente p1
LEFT JOIN tbl_cartellaclinica ON tbl_cartellaclinica.pz_fk_id= p1.id
JOIN tbl_progetto ON tbl_progetto.cc_id_fk = tbl_cartellaclinica.cc_id
LEFT JOIN tbl_trattamenti ON tbl_progetto.pr_id = tbl_trattamenti.pr_fk_id
WHERE
p1.id=77 AND
SUBSTR(trt_note,1,11)="Appuntamento"
GROUP BY MESE, GIORNI
ORDER BY p1.id, ANNO, MESE
sensorario
(Sensorario)
September 8, 2012, 11:49am
5
Ok, ma il codice php che lo compone com’è fatto?
paskuale
(Pellicanipasquale)
September 8, 2012, 11:53am
6
$rowsAppuntamenti=Yii::app()->db->createCommand($query)->queryAll();
poi provo con:
foreach($rowsAppuntamenti as $gt)
{
$meseTmp = $gt['MESE'];
echo $gt['MESE'];
while($meseTmp == $gt['MESE'])
{
echo $gt['GIORNI']
$meseTmp = $gt['MESE'];
}
}
nonzod
(Nicola)
September 12, 2012, 8:31am
7
Non ho mica capito che devi fare, comunque per ordinare gli array guarda qua tra le funzioni *sort
Comunque se tu usi come chiave anno e mese, mettili anche come chiave dell’array con dentro i giorni!
sensorario
(Sensorario)
September 19, 2012, 6:09am
8
Hai trovato una soluzione Paskuale? Puoi postarcela qui?
paskuale
(Pellicanipasquale)
September 19, 2012, 8:42pm
9
Scusate purtroppo il tram-tram quotidiano mi ha distolto … in realtà era sufficiente una iterazione ben fatta, incollo il codice:
foreach($rowsAppuntamenti as $rt)
{
if($rt['MESE']!= $m)
{
//nuova riga
$m = $rt['MESE'];
$y+=6;
$x=10;
$x_giorni=38;
$pdf->MultiCell('', '', 'Nel mese di '.$mesi[$m-1].':', 0, 'L', false, 0, $x, $y, true);
}
$x_giorni+=8;
$pdf->MultiCell('', '', $rt['GIORNO'].';', 0, 'L', false, 0, $x_giorni, $y, true);
}
… quando cambia il mese …
if($rt['MESE']!= $m)
… mi sposto sulla riga successiva!
mdomba
(Maurizio Domba Cerin)
September 20, 2012, 10:25am
10
Sicome l’array te lo fai da te… .perche non lai struturatto cosi:
array(
'anno' => array(
'mese' => array (
'giorni'
)
)
)
Occupa meno memoria ed e piu facile ha traversarlo.
mdomba
(Maurizio Domba Cerin)
September 20, 2012, 10:29am
11
Farlo e semplice
foreach($rowsAppuntamenti as ...)
$array[ANNO][MESE][GIORNO] = <datti/valori per questo giorno>;
zaccaria
(Matteo Falsitta)
September 25, 2012, 10:00am
12
E perche’ fai un ciclo per creare l’array e poi un’altro per stamparlo?
Non puoi stampare e basta?