tarun Posted March 10, 2007 Share Posted March 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
tarun Posted March 11, 2007 Author Share Posted March 11, 2007 BuMp Quote Link to comment Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 <?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']); ?> Quote Link to comment Share on other sites More sharing options...
Glyde Posted March 11, 2007 Share Posted March 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 11, 2007 Share Posted March 11, 2007 There won't be two in there with the same title as the second would have overwritten the first when added Quote Link to comment Share on other sites More sharing options...
tarun Posted March 11, 2007 Author Share Posted March 11, 2007 Thnx Every1 I Really Appreciate It Quote Link to comment Share on other sites More sharing options...
Glyde Posted March 11, 2007 Share Posted March 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.