i have PHP code with loop:
$explodeResult=explode(", ",$serviceName);
foreach($explodeResult as $value)
{
$sql = "SELECT id,parent,code,name,xs1 as DOWNLOAD, xs2 as UPLOAD
FROM sc_params
WHERE rfen = 'SERVICE_REQUESTED'
AND code = :param1
OR code IN
(
SELECT code
FROM sc_params
WHERE rfen = 'SERVICE_REQUESTED'
AND id = (
SELECT parent
FROM sc_params
WHERE rfen = 'SERVICE_REQUESTED'
AND code = :param1 )
)
";
$stmt = oci_parse($this->_conn,$sql);
oci_bind_by_name($stmt, ":param1", $value);
$rs = oci_execute($stmt);
if (!$rs) {
$error = oci_error();
$this->_err = $error;
return false;
}
$product = Array();
$idx = $idx2 = 0;
while ($data = oci_fetch_array($stmt, OCI_BOTH)) {
if($data['PARENT'] == 0) {
$idx++;
$product[$idx]['id'] = $data['ID'];
$product[$idx]['name'] = $data['NAME'];
}
else {
$product[$idx][0]['attributeName'] = 'DOWNLOAD';
$product[$idx][0]['attributeValue'] = $data['DOWNLOAD'];
$product[$idx][1]['attributeName'] = 'UPLOAD';
$product[$idx][1]['attributeValue'] = $data['UPLOAD'];
}
}
print_r ($test_array);
Data from query:
ID NAME PARENT DOWNLOAD UPLOAD
1 INTERNET 0 null null
10 SPEED 1 2048 512
2 VOICE 0 null null
12 PSTN 2 null null
the array result is:
Array ( [1] => Array ( [id] => 1 [name] => INTERNET [0] => Array ( [attributeName] => DOWNLOAD [attributeValue] => 2048 )
[1] => Array
(
[attributeName] => UPLOAD
[attributeValue] => 512
)
)
[2] => Array
(
[id] => 2
[name] => VOICE
[0] => Array
(
[attributeName] => DOWNLOAD
[attributeValue] =>
)
[1] => Array
(
[attributeName] => UPLOAD
[attributeValue] =>
)
)
)
But i just want show the attributeName and attributeValue for internet only.. i tried to add if($data['NAME'][0]='INTERNET') below while, but it doesn't work, VOICE still has attributeName and attributeValue. Please Help. Thanks
vardumpof$data?if($data['NAME'][0]=='INTERNET')1) Shouldn't your conditional be using '==' vs '=' and 2) you be comparing to$data['NAME']instead of$data['NAME'][0]?