mardi 4 août 2015

Append/delete items from array in php/html file

I am a PHP beginner and need some help.

I have a config.data file that has the $logins array serialized in it. (thanks @Barmar!) I have signin.php (below) which I would like to modify in the following way:

  1. Add a 'add project' button which would append the info to the $logins array
  2. Add a 'delete project' button which would delete the info to the $logins array.

Any help to accomplish these two goals would be appreciated!

config.data:

$logins = array(
'project1' =>
        array(
        'password' => 'mypassword',
        'title' => 'Capacitors Project Planner',
        'emails' => array('myweb@mywebsite.com')
         ),
'project2' =>
    array(
        'password' => 'mypassword2',
        'title' => 'My second project',
        'emails' => array('manager@youwebsite.com',
                        'worker@youwebsite.com')
        )
);

signin.php:

require_once( 'config.php' );
//displays arrays
<table class="table" border='1'>
<thead>
    <tr>
    <th> Project name</th>
    <th> Project Login</th>
    </tr>
    </thead>
<tbody>
<?php foreach( $logins as $projname => $projinfos ): ?>
    <tr>
        <td><?= $projname ?></td>
        <td><?= $projinfos["title"]?>
        </td>
        </tr>

<?php endforeach; ?>
</tbody>
</table>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire