0

わかりました、私は自分の PC で頭を悩ませています…。何が起こっているのかわかりません。PHP を使用して、リモート データベースへの SOAP 呼び出しを行っています... 4 つのクエリを実行し、2 つの多次元配列をマージして返しています。

配列はきれいに見えますが、結果を表示すると繰り返しています。

呼び出し後の一例を次に示します。

$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>';
}

返された配列から繰り返される問題を次に示します。

[11] => Array ( 
                    [Product] => Some Product 
                    [Color] => Some Color 
                    [Type] => C 
                    [Length] => 150 
              )

ただし、同じことが繰り返されます..これは、ほんの一握りの製品でのみ行われます。


  • いくつかの製品
    の色: いくつかの色
    サイズ: 150
    価格: 4.79

    </li>
    


  • いくつかの製品
    の色: いくつかの色
    サイズ: 150
    価格: 4.79

    </li>
    


  • いくつかの製品
    の色: いくつかの色
    サイズ: 150
    価格: 4.79

    </li>
    


  • いくつかの製品
    の色: いくつかの色
    サイズ: 150
    価格: 4.79

    </li>
    
  • 4

    3 に答える 3

    0

    わかりました、答えを更新するつもりでした。foreach の最後に if ステートメントを置いていたので、そこにない要素の要素が繰り返されていました。元の if ステートメントが 2 つあったので、最後の if ステートメントを、基本的に表す if ステートメントに移動したところ、機能しました。

    ここに最初のコード例があります:

    <?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;
    
    
    }
    
    
    
    
    }
    }
    
    
    
    ?>
    

    これが変更点です..私はこのプロジェクトに長い間取り組んできたので、知っておくべき小さなことを見落としています。

    <?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;
    
    
    }
    
    }
    
    
    
    
    
    
    
    
    
    }
    }
    
    
    
    ?>
    

    アドバイスと助けをありがとう

    于 2013-06-27T19:39:59.023 に答える