swatisonee Posted March 20, 2006 Share Posted March 20, 2006 Hi,I've set up a simple pm system and need to set up a deletion of messages when the message is read by the recepient. Since recepients can be multiple, my system must allow deletion only when all recepients have read a message. Problem is the order in which the message is read can be different.Here's what I have :[code]$sqla= "SELECT * FROM `Messages` WHERE `MID`= $a"; $resulta = mysql_query($sqla) or die (mysql_error($sqla); if ($myrowa = mysql_fetch_array($resulta)) { do {$toall=$myrowa["To"];$seenby = $myrowa["Seen_By"];if ( $toall == $seenby){$sqly = " DELETE FROM `Messages` WHERE `MID`= $a ";$resulty = mysql_query($sqly); if ( !@mysql_query($resulty) ) { echo "<p>Message with <b>ID $a</b> has been deleted successfully."; } else { die ( "Unable to delete this message as it has not been viewed by all recepients" ); } }[/code]However,if $toall = uid1, uid3, uid4 (in that order) and $seen_by = uid3, uid1,uid4, uid3 (in that order as one recepient can view a message multiple times)then $toall will not be equal to $seenby.So , i thought of extracting the individual userids through the array by referring to the info. given at[a href=\"http://builder.com.com/5100-6371-5792851.html\" target=\"_blank\"]http://builder.com.com/5100-6371-5792851.html[/a]and thats where I'm stuck because the codes dont work and when I echo $ta1 and $sb1 ,all i get is Ärray1 and the messages get deleted regardless of whether they've been read or not. Here's what I have and would appreciate if someone to correct me .Thanks.[code]<?$sqla= "SELECT * FROM `Messages` WHERE `MID`= $a"; $resulta = mysql_query($sqla) or die (mysql_error($sqla); if ($myrowa = mysql_fetch_array($resulta)) { do {$toall=$myrowa["To"];$seenby = $myrowa["Seen_By"];$ta1= array(",", $toall );$ta2=sort($ta1);$sb = (array_unique($seenby));$sb1 = array(",", $sb );$sb2= sort($sb1);if ($ta2==$sb2){$sqly = " DELETE FROM `Messages` WHERE `MID`= $a ";$resulty = mysql_query($sqly); if ( !@mysql_query($resulty) ) { echo "<p>Message with <b>ID $a</b> has been deleted successfully."; } else { die ( "Unable to delete this message as it has not been viewed by all recepients" ); } } } while ($myrowa = mysql_fetch_array($resulta)); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/5334-trouble-with-comparing-arrays/ Share on other sites More sharing options...
TEENFRONT Posted March 20, 2006 Share Posted March 20, 2006 no idea if this will work lol..totally untested and a stab in the dark.. what about doing this?so say $seenby = uid1, uid2, uid3, uid2sort($seenby); // so now $seenby should = uid1, uid2, uid2, uid3$seenbyclean = array_unique($seenby); // gets rid of duplicatesecho $seenbyclean ; // should output uid1, uid2, uid3like i said though..no idea if this wud work.. Link to comment https://forums.phpfreaks.com/topic/5334-trouble-with-comparing-arrays/#findComment-18993 Share on other sites More sharing options...
Barand Posted March 20, 2006 Share Posted March 20, 2006 The rods one creates for one's back when data isn't normailized!Try[code]$toall=$myrowa["To"];$seenby = $myrowa["Seen_By"];$toArray = array_unique(explode(', ', $toall)); // assumes comma-space as separator$sbArray = array_unique(explode(', ', $seenby)); // assumes comma-space as separatorsort($toArray);sort($sbArray);if ($toArray == $sbArray) { # ok to delete}else { # not seen by all}[/code] Link to comment https://forums.phpfreaks.com/topic/5334-trouble-with-comparing-arrays/#findComment-19122 Share on other sites More sharing options...
swatisonee Posted March 22, 2006 Author Share Posted March 22, 2006 More like buying a tie and then finding a shirt to go with it !As always, thank you !I dont know if you saw my other post on the next rod I need to create but i think its the most serious of all the issues i've run into thus far. Would you have a moment to glance thru it and see what I could try ?[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=88832\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=88832[/a]Thanks again !Swati Link to comment https://forums.phpfreaks.com/topic/5334-trouble-with-comparing-arrays/#findComment-19557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.