0

私はこの次のxml部分を持っています

<Form>
      <Team id="3041" name="Gefle" position="7" played="6" won="2" draw="3" lost="1" scored="10" against="9" points="9,00" form="D-W-D-W-D-L" />
      <Team id="3051" name="Halmstad" position="13" played="6" won="1" draw="3" lost="2" scored="7" against="9" points="6,00" form="D-W-L-D-L-D" />
</Form>

次のような値を取得します。

$form=array();
for ($i = 0; $i < sizeof($veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team); $i++) {
    $form['id'][$i]         = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['id'];
    $form['name'][$i]       = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['name']; 
    $form['position'][$i]   = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['position'];
    $form['played'][$i]     = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['played'];
    $form['won'][$i]        = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['won'];
    $form['draw'][$i]       = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['draw'];
    $form['lost'][$i]       = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['lost'];
    $form['scored'][$i]     = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['scored'];
    $form['against'][$i]    = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['against'];
    $form['points'][$i]     = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['points'];
    $form['form'][$i]       = $veri->Sport->Country->Tournament->Season->Stage->Match->Form->Team[$i]['form'];
//  echo $form['id'][$i] ."<br/>".$form['name'][$i] ."<br/>".$form['position'][$i]."<br/>".$form['played'][$i] ."<br/>".$form['won'][$i]."<br/>" .$form['draw'][$i]."<br/>".$form['lost'][$i]."<br/>".$form['scored'][$i] ."<br/>".$form['against'][$i] ."<br/>".$form['points'][$i] ."<br/>".$form['form'][$i]. "<hr/>"; 
}

今のところ問題ありません。しかし、これらのレコードを次のように db に挿入しようとすると:

$sorgu      = mysql_query("SELECT * FROM takim WHERE id='$homeid'");
$etki       = mysql_affected_rows();
if ($etki > 0) {
    for ($i = 0; $i < sizeof($form['id']); $i++) {
        if ($form['id'][$i] == $homeid) {
            $takiminid      = $i;
            $takimid        = $form['id'][$takiminid];
            $takimisim      = $form['isim'][$takiminid];
            $takimpozisyon  = $form['pozisyon'][$takiminid];
            $takimplayed    = $form['played'][$takiminid];
            $takimwon       = $form['won'][$takiminid];
            $takimlost      = $form['lost'][$takiminid];
            $takimdraw      = $form['draw'][$takiminid];
            $takimscored    = $form['scored'][$takiminid];
            $takimagainst   = $form['against'][$takiminid];
            $takimpoints    = $form['points'][$takiminid];
            $takimform      = $form['form'][$takiminid];
            $sorgu          = mysql_query("UPDATE takim SET isim='$takimisim', pozisyon='$takimpozisyon', oynanan='$takimplayed', kazan='$takimwon', beraber='$takimdraw', kaybet='$takimlost', scored='$takimscored', against='$takimagainst', points='$takimpoints', form='$takimform' WHERE id='$takimid'");
        }
    }
}
else { 
    for ($i = 0; $i < sizeof($form['id']); $i++) {
        if ($form['id'][$i] == $homeid) {
            $takiminid      = $i;
            $takimid        = $form['id'][$takiminid];
            $takimisim      = $form['isim'][$takiminid];
            $takimpozisyon  = $form['pozisyon'][$takiminid];
            $takimplayed    = $form['played'][$takiminid];
            $takimwon       = $form['won'][$takiminid];
            $takimlost      = $form['lost'][$takiminid];
            $takimdraw      = $form['draw'][$takiminid];
            $takimscored    = $form['scored'][$takiminid];
            $takimagainst   = $form['against'][$takiminid];
            $takimpoints    = $form['points'][$takiminid];
            $takimform      = $form['form'][$takiminid];
            $sorgu          = mysql_query("INSERT INTO takim (id, isim, pozisyon, oynanan, kazan, beraber, kaybet, scored, against, points, form) VALUES ('$takimid', '$takimisim', '$takimpozisyon', '$takimplayed', '$takimwon', '$takimdraw', '$takimlost', '$takimscored', '$takimagainst', '$takimpoints', '$takimform')");
        }
    }
}

このエラーが発生します:

Notice: Undefined index: id in C:\xampp\htdocs\Demo\index.php on line 154

これは

for ($i = 0; $i < sizeof($form['id']); $i++) { in else part.

dbに値を挿入しません。問題に見えるのは?

4

1 に答える 1

0

私はそれを考え出した。問題は、2つのオブジェクトを比較しようとしていたことでした

if ($form['id'][$i] == $homeid)

ここ。これら 2 つが等しいかどうかを正常に比較できるようにするために、if ステートメントのすぐ上で型を int に設定し、if ステートメント内で型をオブジェクトに戻します。だから私の解決策は単純でした:

        settype($form['id'][$i], "integer");
        settype($homeid, "integer");
        if ($form['id'][$i] == $homeid) {
            settype($form['id'][$i], "object");
            settype($homeid, "object");
            $takiminid      = $i;
            $takimid        = $form['id'][$takiminid];
            $takimisim      = $form['name'][$takiminid];
            $takimpozisyon  = $form['position'][$takiminid];
            $takimplayed    = $form['played'][$takiminid];
            $takimwon       = $form['won'][$takiminid];
            $takimlost      = $form['lost'][$takiminid];
            $takimdraw      = $form['draw'][$takiminid];
            $takimscored    = $form['scored'][$takiminid];
            $takimagainst   = $form['against'][$takiminid];
            $takimpoints    = $form['points'][$takiminid];
            $takimform      = $form['form'][$takiminid];
            $sorgu          = mysql_query("UPDATE takim SET isim='$takimisim', pozisyon='$takimpozisyon', oynanan='$takimplayed', kazan='$takimwon', beraber='$takimdraw', kaybet='$takimlost', scored='$takimscored', against='$takimagainst', points='$takimpoints', form='$takimform' WHERE id='$takimid'");
        }
于 2013-11-11T12:08:52.170 に答える