0

理解を深めるために、私の仕事について説明します。フォームを持つ携帯電話を 1 つずつリストに追加するには、PHP でツールを作成する必要があります。後でリストを CSV/XML ファイルにエクスポートする必要があります。これは Array オブジェクトで行われます。私の問題は、フォームでモバイルを入力できることですが、それらはオーバーライドされて追加されません。そのため、リストには一度に 1 つの電話しかありません。これまでの私のコード: HTML:

      <div>
    <form name="Eingabe" action="handler.php" method="POST">
        <label for="Hersteller">Hersteller</label>
        <input id="Hersteller" name="Hersteller" type="text"><br>
        <label for="Modell">Modell</label>
        <input id="Modell" name="Modell" type="text"><br>
        <label for="Preis">Preis</label>
        <input id="Preis" name="Preis" type="number" min="1" max="1000"><br>
        <label for="Seriennummer">Seriennummer</label>
        <input id="Seriennummer" name="Seriennummer" type="text"><br>
        <br>
        <input name="Senden" type="submit" value="Speichern">
    </form>
  </div>

リスト:

    <?php


class handy /* extends guid */ {

    private $id;
    private $hersteller;
    private $modell;
    private $seriennr;
    private $preis;

    public function setid($id)
    {
        $this->id = $id;
    }

    public function sethersteller($hersteller)
    {
        $this->hersteller = $hersteller;
    }

    public function setmodell($modell)
    {
        $this->modell = $modell;
    }

    public function setseriennr($seriennr)
    {
        $this->seriennr = $seriennr;
    }

    public function setpreis($preis)
    {
        $this->preis = $preis;
    }

    public function getid()
    {
        return $this->id;
    }

    public function gethersteller()
    {
        return $this->hersteller;
    }

    public function getmodell()
    {
        return $this->modell;
    }

    public function getseriennr()
    {
        return $this->seriennr;
    }

    public function getpreis()
    {
        return $this->preis;
    }

}

?>
<?php
class handyliste extends ArrayObject {

public function addhandy($i, $hdy)
{
    $this->offsetSet($i, $hdy);
}
?>

ハンドラ:

        $h = new handy();
    $h->sethersteller($_POST['Hersteller']);
    $h->setid(uniqid());
    $h->setmodell($_POST['Modell']);
    $h->setpreis($_POST['Preis']);
    $h->setseriennr($_POST['Seriennummer']);
    $hl = new handyliste();
    $hl->addhandy(null, $h);
 echo "<table>";
    echo "<thead><tr><th>ID</th><th>Hersteller</th><th>Modell</th><th>Seriennummer</th><th>Preis</th></tr></thead>";
    foreach ($hl as $h)
    {
        echo "<tr><td>";
        echo $h->getid() . "</td><td>";
        echo $h->gethersteller() . "</td><td>";
        echo $h->getmodell() . "</td><td>";
        echo $h->getseriennr() . "</td><td>";
        echo $h->getpreis() . "€&lt;/td></tr>";
    }
    echo "</table>";

誰かが助けてくれることを願っています。通常の配列では簡単だと思いますが、以前は配列オブジェクトを扱ったことがありませんでした。

4

1 に答える 1