Solved

Deleting "messages" from the inbox

Posted on 2009-04-08
7
264 Views
Last Modified: 2013-12-12
what would the best method be to delete the messages you dont want by checking the check boxes?
<table width="80%" class='forum'>

  <tr>

    <td><table width="100%" class='maintable'>
 

<tr class='headline'>

  <td align="center"><b><u>Select</u></b></td>

  <td align="center">Status</td>

  <td align="center">Sender</td>

  <td align="center">Image</td>

  <td><b><u>Subject</u></b></td>

  <td>Sent On</td>

  </tr>

<?php

		//Ok cool, now we stick it all into an array and we will dispaly it now

		while($inbox = mysql_fetch_array($sqlinbox))

			{

			//These are the variables we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it

			$pm_id = $inbox['id'];

			$sender = $inbox['sender'];

			$subject = $inbox['subject'];

			$time = $inbox['time'];

			$new = $inbox['recieved'];

			

			//So lets show the subject and make that a link to the view message page, we will send the message id through the URL to that page so it can be displayed

			//And also let the person wee who sent it to them, if you want you can make that some sort of a link to view more stuff about the user, but Im not doing that here, I did it for my game though, pretty much same as the viewmsg.php page but a different page, and with the senders id

			//And finally the checkboxes that are all stuck into an array and if they are selected we stick the private message id into the array

			//I will only let my users have a maximum of 50 messages, remeber that ok? Because that's the value I will use later for things

			?>

 <tr <?php if($important==1) {

    $class = "mainrow1";

} else {

    $class = "mainrow";

}  ?> class="<? echo $class?>">

   <td width="5%" height="18" align="center" valign="top"><input name="pms[]" type="checkbox" value="<?php echo $pm_id; ?>" />

   <td width="6%" height="18" align="center" valign="top"><?php if  ($new == 0 ){echo 'Unread';} else {echo 'Read';} ?>   

   <td width="9%" align="center" valign="top"><p><a href="http://www.runningprofiles.com/members/<?php echo $sender; ?>"><?php echo $sender; ?></a></p>

     <p><a href="http://www.runningprofiles.com/members/<?php echo $sender; ?>"></a></p>

     <p>&nbsp;       </p>

   <td width="9%" align="center" valign="top"><a href="http://www.runningprofiles.com/members/<?php echo $sender; ?>">

   <?php $sender = $inbox['sender']; $getuser="SELECT * FROM users WHERE Username = '$sender' "; 

$getuser2=mysql_query($getuser) or die("Could not get user")  ;
 

while($getuser3=mysql_fetch_array($getuser2)){
 

  $getuser3['image']=strip_tags($getuser3['image']);

  $image = $getuser3['image'];

echo "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\"  />";

  }?>

   </a>   

   <td width="37%" align="center" valign="top"><p align="left"><a href="index.php?page=viewmsg&msg_id=<?php echo $pm_id; ?>"><?php echo $subject; ?></a>

     </td>

   <td align="left" valign="top"><?php $time1 = date("F j Y, g:i a", $time); echo $time1; ?>     <div align="left"></div></td>

   </tr>

<?

}

?>

 <tr <?php if($important==1) {

    $class = "mainrow1";

} else {

    $class = "mainrow";

}  ?> class="<? echo $class?>">

   <td height="19" colspan="6" align="center" valign="middle"><input type="submit" name="Submit" value="Delete Selected">     </tr>
 

</table></td>

  </tr>

Open in new window

0
Comment
Question by:runnerjp
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24095654
foreach message have a checkbox with a control array (same name with "[ ]". for example:

pseudo code:
<input name="checkmessage[]" value="{InsertMessageIdHere}"> Foo Bar
<input name="checkmessage[]" value="{InsertMessageIdHere}"> Hello World
<input name="checkmessage[]" value="{InsertMessageIdHere}"> Nerd

pseudo display:
[ ] Foo Bar
[x] Hello World
[x] Nerd

In processing you would run a for loop through the Ids to build a DELETE query,

Mission complete.


0
 
LVL 10

Expert Comment

by:ollyatstithians
ID: 24095668
If you want the hotmail style checkboxes and a delete button, make a form like the one in the code below. Look at the $_POST array. You can use this data to make an SQL update or delete statement or whatever you need.

Olly.
<?php

// Test data

	$messages[] = array('id'=>'1', 'subject'=>'Message1', 'date'=>'20090408');

	$messages[] = array('id'=>'2', 'subject'=>'Message2', 'date'=>'20090408');

	$messages[] = array('id'=>'3', 'subject'=>'Message3', 'date'=>'20090408');

	$messages[] = array('id'=>'4', 'subject'=>'Message4', 'date'=>'20090408');

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

	<title>Temp</title>

	<style type="text/css">

	</style>

</head>

<body>

  <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>"><!-- you should always use the POST method to make changes to your database -->

		<input type="submit" name="operation" value="Delete" />

		<input type="submit" name="operation" value="Move" />

		<table>

			<thead>

				<tr><th>select</th><th>Subject</th><th>Date</th></tr>

			</thead>

			<tbody>

<?php

	foreach($messages as $message)

	{

?>

				<tr><td><input type="checkbox" name="selection[]" value="<?php echo $message['id']; ?>" /></td><td><?php echo $message['subject']; ?></td><td><?php echo $message['date']; ?></td></tr>

<?php

	}

?>

			</tbody>

		</table>

	</form>

	<pre>

<?php

	var_dump($_POST);

?>

	</pre>

</body>

</html>

Open in new window

0
 

Author Comment

by:runnerjp
ID: 24095794
ok if my vardump is array(2) { ["pms"]=>  array(2) { [0]=>  string(2) "29" [1]=>  string(2) "28" } ["Submit"]=>  string(15) "Delete Selected" }

how would i get which checkboxes where selected so i can do this $delete="DELETE FROM messages WHERE id=??  

in other worlds how do i perform a get on the checkboxes?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:ollyatstithians
ID: 24095979
That is what the pms array is: a list of the ids that you want to delete.
Make your where clause like this:

WHERE id in ({list of ids from the array})

Olly.
0
 

Author Comment

by:runnerjp
ID: 24096029
but im confused what the  would look like??

$delete="DELETE FROM messages WHERE id=?????";
      mysql_query($delete) or die("Error: " . mysql_error());
0
 
LVL 10

Accepted Solution

by:
ollyatstithians earned 500 total points
ID: 24096152
Use the implode() function to make a list out of your array of ids.

Olly.
$delete="DELETE FROM messages WHERE id in (".implode(',', $_POST['pms']).")";

      mysql_query($delete) or die("Error: " . mysql_error());

Open in new window

0
 

Author Closing Comment

by:runnerjp
ID: 31567955
ahh implode!!!!!! thats why it wouldnt work...thanks :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now