I have a query which as only one row has a result and I am trying to store its content inside an array. The problem is that the code is putting inside the array $vs31 five times the real result and I don't understand why.
$query1 = "SELECT PROCESSO,DATAMSG, CATEGORIA_DESC, VALOR, CRITICO FROM TABLEX";
$result1 = oci_parse($connect, $query1);
oci_execute($result1);
$c1=array();
oci_fetch_all($result1, $c1, null, null, OCI_FETCHSTATEMENT_BY_ROW);
$f=0;
foreach ($c1 as $row) {
foreach ($row as $key => $value) {
$vs3=array();
$f++;
$vs3['id']= $f;
$vs3['title']='VSC - '.$row['CATEGORIA_DESC'];
$vs3['startdate']=$row['DATAMSG'];
$vs3['enddate']=$row['DATAMSG'];
$vs3['description']= 'VALOR - '.$row['VALOR'];
$vs3['date_display']='ho';
$vs3['icon']='plus_blue.png';
$vs3['importance']='30';
$vs3['css_class']='hot-event';
array_push($vs31,$vs3);
}
}
print_r($vs31);
What I get:
Array
(
[0] => Array
(
[id] => 103
[title] => VSC - ECG_HR
[startdate] => 2015-04-27 23
[enddate] => 2015-04-27 23
[description] => VALOR - 59
[date_display] => ho
[icon] => plus_blue.png
[importance] => 30
[css_class] => hot-event
)
[1] => Array
(
[id] => 104
[title] => VSC - ECG_HR
[startdate] => 2015-04-27 23
[enddate] => 2015-04-27 23
[description] => VALOR - 59
[date_display] => ho
[icon] => plus_blue.png
[importance] => 30
[css_class] => hot-event
)
[2] => Array
(
[id] => 105
[title] => VSC - ECG_HR
[startdate] => 2015-04-27 23
[enddate] => 2015-04-27 23
[description] => VALOR - 59
[date_display] => ho
[icon] => plus_blue.png
[importance] => 30
[css_class] => hot-event
)
[3] => Array
(
[id] => 106
[title] => VSC - ECG_HR
[startdate] => 2015-04-27 23
[enddate] => 2015-04-27 23
[description] => VALOR - 59
[date_display] => ho
[icon] => plus_blue.png
[importance] => 30
[css_class] => hot-event
)
[4] => Array
(
[id] => 107
[title] => VSC - ECG_HR
[startdate] => 2015-04-27 23
[enddate] => 2015-04-27 23
[description] => VALOR - 59
[date_display] => ho
[icon] => plus_blue.png
[importance] => 30
[css_class] => hot-event
)
)
What it want:
Array
(
[0] => Array
(
[id] => 103
[title] => VSC - ECG_HR
[startdate] => 2015-04-27 23
[enddate] => 2015-04-27 23
[description] => VALOR - 59
[date_display] => ho
[icon] => plus_blue.png
[importance] => 30
[css_class] => hot-event
)
)
$vs31array. That's because your table has 5 entries and you're not using a WHERE clause to filter them. If you want a different output, try changing your query or use LIMIT 1.idfield. If you doecho '<pre>'; print_r($c1);before theforstatement, what do you get?