hey guys,

any tricks that i can use to link a table row with an employee ID that comes from a db ?
heres the menu code, where the link must happen, so i can call other functions like delete and modify.
sorry it's french, supprimer = delete, modifier = modify. The rest i dont think its important to translate.

  function menu() {
    $data = new dbFetch();
    $data = explode("|", $data->tableau());

    $chaine = "<table>
            <tr>
                <th>empID</th>
                <th>Nom</th>
                <th>Adresse</th>
                <th>Salaire</th>
            </tr>";

    for($i=0; $i<count($data)-1; $i++){
        $chaine .= "<tr>";
        $data2 = explode(";", $data[$i]);

        for($j=0; $j<count($data2)-1; $j++)
                $chaine .= "<td>$data2[$j]</td>";

        $chaine .= "<td>
                    <input type='hidden' name='empID' value='".$data2[0]."'>
                    <input type='submit' name='oper' value='Supprimer'>
                    <input type='submit' name='oper' value='Modifier'></td>
                    </tr>";
    }//End for 
    $chaine .= "</table>";
    $chaine .= "<input type='submit' name='oper' value='Inserer'/>";

    return $chaine;
  }//End menu

now ? does my $data2[0] really independant on each row ? because when i change the hidden to text on empID, i really get the value im supposed to get.

or the form consider the supprimer and modifier buttons like 1 for the all table ?

when i try to delete or modify something, it always pick the last entry on the db, which would be the last row in the table.

thx guys.

Dark

Recommended Answers

All 2 Replies

Just needs a new form tag for every row:

for($i=0; $i<count($data)-1; $i++){
        $chaine .= "<tr>";
        $data2 = explode(";", $data[$i]);
        for($j=0; $j<count($data2)-1; $j++)
                $chaine .= "<td>$data2[$j]</td>";
        $chaine .= "<td>
                    <form>
                    <input type='hidden' name='empID' value='".$data2[0]."'>
                    <input type='submit' name='oper' value='Supprimer'>
                    <input type='submit' name='oper' value='Modifier'>
                    </form>
                    </td>
                    </tr>";
    }

That isolates the inputs so other inputs in different forms with the same input name don't overwrite

WOW! so simple.

thx buddy, really appreciated.

Dark

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.