xyn Posted July 16, 2006 Share Posted July 16, 2006 Hi guys,I have my private messenger inbox and I wanted my members to be-able to tick a box and delete that one ID so they can delete multiple messages at a time, Say if a member has 10 messages and wants to delete 6 at the same time, he ticks the 6 boxs and delets them all.My problem is When i killed the Code and echod the array list It outputted 1 item out of the two i ticked. any ideas?my code:[code=php:0]<?PHPinclude "Session.php";$act = $_GET['act']; if( !$act ){include "db.php"; echo '<form method="post" action="?act=delete">';$sql = mysql_query("SELECT id,sendto,sendfrom,subject FROM pm WHERE sendto='{$_SESSION['user']['user']}'"); while( $udat = @mysql_fetch_array($sql, MYSQL_NUM)) { echo '<p>ID: '.$udat[0].'<br>To: '.$udat[1].'<br>From: '.$udat[2].'<br>Subject: '.$udat[3].'<br><input type="checkbox" name="del" value="'.$udat[0].'"></p>'; } echo '<input type="submit" value="Delete"></form>'; } elseif( $act == delete ) { if(isset($_POST['del']) && empty($_POST['del'])) { echo "Please hylight the post you wish to delete."; echo "<BR>"; echo "<a href=1test.php>Back</a>"; exit; } echo $_POST['del']; exit; $del[] = $_POST['del']; if(is_array($del)) { foreach($del as $key => $value) { $sql_delete = "".$value." , "; } include "db.php"; $db = mysql_connect("localhost", $login, $pwd); mysql_select_db("zroxxco_members"); $dsql = "DELETE * FROM pm WHERE id='$sql_delete'"; mysql_query($dsql, $db); echo "You have deleted messages #'.$sql_delete.'"; } exit; } else { die('error: unknown location.'); } ?>[/code] Quote Link to comment Share on other sites More sharing options...
Joe Haley Posted July 16, 2006 Share Posted July 16, 2006 $del[] = $_POST['del'];if(is_array($del)){foreach($del as $key => $value){$sql_delete = "".$value." , ";}Wont the array only itterate once, as $del would only contain $del[0] with the value of $_POST['del'] ? Quote Link to comment Share on other sites More sharing options...
xyn Posted July 16, 2006 Author Share Posted July 16, 2006 probably, thats what confusig me.. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 16, 2006 Share Posted July 16, 2006 Have your checkboxes named something like "del[]" and give each the value of te records id[code]<input type='checkbox' name='del[]' value'$id' >[/code]When you process the form data you can then delete them all with a single query with[code]$deleteList = join (',' , $_POST['del']);mysql_query ("DELETE FROM tablename WHERE id IN ($deleteList)" );?>[/code] Quote Link to comment Share on other sites More sharing options...
xyn Posted July 16, 2006 Author Share Posted July 16, 2006 Ah, thanks :] 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.