Ok, I am beating my head on my PC…. I do not know what is going on. I’m using PHP to make a soap call to a remote database… I am running 4 queries, merging two multidimensional arrays and returning them.
The array looks clean, but when I display the results, they are repeating.
Here is one example after call:
$row = $response;
$count = count($row);
for($i=0;$i<=$count-1;$i++){
$product = $row[$i]['Product'];
$color = $row[$i]['Color'];
$type = $row[$i]['Type'];
$length = $row[$i]['Length'];
$render = '<li><div id="somediv">strong>' . $product . '</strong><br />Color: ' . $color . '<br />' . ‘ Size: ' . $length . '<input type="button" value="value" onclick="someaction(' . $i . ')" />' . '</div></li>';
}
Here is a repeated problem from the array returned :
[11] => Array (
[Product] => Some Product
[Color] => Some Color
[Type] => C
[Length] => 150
)
However the it repeats the same occurrence.. it only does this with a handful of products:
</li>
</li>
</li>
</li>
Ok I was going to update my answer. I had put to if statements at the end of the foreach, and it would repeat an element for the elements that were not there. I had two original if statements, so I moved the final if statements to the the if statements they basically represented and it worked.
here was first code example:
<?php
$row = $response;
$count = count($row);
for($i=0;$i<=$count-1;$i++){
@$type = $row[$i]['Type'];
if ($type == 'something') {
$someproduct = $row[$i]['someproduct'];
$somecolor = $row[$i]['somecolor'];
$length = $row[$i]['Length'];
if ($type == 'this') {
$img = 'myimage';
$this = $img . '<div id="somediv"><br /><strong>' . $someproduct . 'somecolor: ' . $somecolor . '<input type="button" value="value" onclick="somefunction(' . $i . ')" />' . '</div></div></li>';
}
if ($type == 'that') {
$img = 'myimage';
$that = $img . '<div id="somediv"><br /><strong>' . $someproduct . 'somecolor: ' . $somecolor . '<input type="button" value="value" onclick="somefunction(' . $i . ')" />' . '</div></div></li>';
}
if (!isset($whatever) || $whatever == 'that') {
echo $that;
}
if (!isset($whatever) || $whatever == 'this') {
echo $this;
}
}
}
?>
Here is the change.. I've been working on this project so long, I'm overlooking small stuff that I should know.
<?php
$row = $response;
$count = count($row);
for($i=0;$i<=$count-1;$i++){
@$type = $row[$i]['Type'];
if ($type == 'something') {
$someproduct = $row[$i]['someproduct'];
$somecolor = $row[$i]['somecolor'];
$length = $row[$i]['Length'];
if ($type == 'this') {
$img = 'myimage';
$this = $img . '<div id="somediv"><br /><strong>' . $someproduct . 'somecolor: ' . $somecolor . '<input type="button" value="value" onclick="somefunction(' . $i . ')" />' . '</div></div></li>';
if (!isset($whatever) || $whatever == 'this') {
echo $this;
}
}
if ($type == 'that') {
$img = 'myimage';
$that = $img . '<div id="somediv"><br /><strong>' . $someproduct . 'somecolor: ' . $somecolor . '<input type="button" value="value" onclick="somefunction(' . $i . ')" />' . '</div></div></li>';
if (!isset($whatever) || $whatever == 'that') {
echo $that;
}
}
}
}
?>
Thanks for the advice and help
Do a print_r($row)
which will show you what is in your array. If the values are there, it's not an issue with the printing, it's with generating the array.
Sorry, I'm a dummy... I forgot I was hidden some values, so it was repeating until the next unhide value was shown