Jump to content

[SOLVED] MultiDimensionalArrays - PM System


tarun

Recommended Posts

My Website Has A PM (PrivateMessaging) System

It Will Use Arrays And The PMs Are Stored In: msgs/$user.php

And Access Using: include("msgs/$user.php");

 

<?php
$msg = array(
  'MsgTitle1'=>array(
    'From1',
    'MsgBody1',
    'TimeReceived1'
  ),
  'MsgTitle2'=>array(
    'From2',
    MsgBody2',
    'TimeReceived2'
  ),
  'MsgTitle3'=>array(
    'From3',
    'MsgBody3',
    'TimeReceived3'
  )
);
?>

 

 

What What The send.php, inbox.php, delete.php Page Look Like

In Other Words How Do I View All The Array Contents (foreach?) And Delete And Add To The Array

 

 

Thnx,

Tarun

Link to comment
Share on other sites

<?php
$msg = array(
  'MsgTitle1'=>array(
    'From1',
    'MsgBody1',
    'TimeReceived1'
  ),
  'MsgTitle2'=>array(
    'From2',
    'MsgBody2',
    'TimeReceived2'
  ),
  'MsgTitle3'=>array(
    'From3',
    'MsgBody3',
    'TimeReceived3'
  )
);

/**
* to list the array
*/

foreach ($msg as $title => $mdata) {
    echo "<br><b>Message title : $title</b><br>";
    foreach ($mdata as $item) {
        echo "$item<br>";
    }    
}

/**
* add new item
*/

$msg['MsgTitle4'] = array ('From4', 'MsgBody4', 'TimeReceived4');

/**
* delete msg2
*/

unset ($msg['MsgTitle2']);
?>

Link to comment
Share on other sites

Don't use the message titles as the offsets, use integers, such as:

<?php
$messageList = array(
     array('title' => 'Message title',
             'sender' => 'sender',
             'body' => 'Body'),
     array('title' => 'Message title',
             'sender' => 'sender',
             'body' => 'Body'));
?>

If you use titles as offsets and two people send a message with the same title, the older one will be removed from the array.

Link to comment
Share on other sites

There won't be two in there with the same title as the second would have overwritten the first when added

If he's simply using fwrite(), then no.  It would just append the data to the end of the file.  But you still just proved my point.  The second message would replace the first, whether it overwrites it from the file, or just doesn't display when printed...either way the first one is gone.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.