coolphpdude Posted July 29, 2008 Share Posted July 29, 2008 At the minute i have a message service on my uni site. Similar to most email sites there is a tick box after the message where you can selet 1 or multiple messages then click a delete button to delete them all. At present my code looks similar to this... echo "<td><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$memo['memo']." '></td>\n"; what i want to know is could the 'value' contain more than one field/variable? At present it only holds the memo_id, would it be possible to hold memo subject '$memo['memo_s']' as well?? If so how do you do it?? Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/ Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 value attribute holds a string...it can be one field from your database...or multiple fields seperated by comma or something else...as far as it is a string, it will work Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602571 Share on other sites More sharing options...
coolphpdude Posted July 29, 2008 Author Share Posted July 29, 2008 so would sumthing like this work... echo "<td><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$memo['memo'].$memo['memo_s']." '></td>\n"; Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602578 Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 yes it will work unless your field dont have single or double quotes..but if you dont put a seperator in between 2 fields..how will you seperate them on next page, or you dont need to do that? Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602596 Share on other sites More sharing options...
coolphpdude Posted July 29, 2008 Author Share Posted July 29, 2008 I basically have this within the same page and the 'delete' button takes you to this section of code and refreshes the page so the memo's you have deleted disapear. // delete message loop switch(@$_GET["action"]) { Case "delete": if(is_array($_POST['checkbox'])) { foreach($_POST['checkbox'] as $memo) { echo "memo subject: $memo_s has been deleted."; mysql_query("DELETE FROM memo WHERE memo_id='$memo'") or die(mysql_error()); } } //echo 'records deleted'; default: so i need to get not just the memo_id but the memo subject as well. any ideas?? Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602603 Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 in form echo "<td><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$memo['memo_id'].";;".$memo['memo_s']." '></td>\n"; in code // delete message loop switch(@$_GET["action"]) { Case "delete": if(is_array($_POST['checkbox'])) { foreach($_POST['checkbox'] as $memo) { $arr = explode(";;", $memo); echo "memo subject: ".$arr[1]." has been deleted."; mysql_query("DELETE FROM memo WHERE memo_id='".$arr[0]."'") or die(mysql_error()); } } //echo 'records deleted'; default: OR you can pass just id from check box and fetch subject again from database for showing subject after deletion.. Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602621 Share on other sites More sharing options...
coolphpdude Posted July 29, 2008 Author Share Posted July 29, 2008 hmm that didn't work... any other ideas?? Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602650 Share on other sites More sharing options...
coolphpdude Posted July 29, 2008 Author Share Posted July 29, 2008 echo "<td><input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$memo['memo"].";;".$memo['memo_s']." '></td>\n"; is echoing... 16;;hand in date so im guessing its taking it all in as one string under $memo instead of 2 seperate variables. I could do another select from the database but with high ammount of users it would be another search query which i could do without if it is possible to pass the two variables. if its not then i will have to do another select query. Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602654 Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 is it showing some error ? try echoing $memo in for loop foreach($_POST['checkbox'] as $memo) { echo $memo."<br/>"; Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602662 Share on other sites More sharing options...
coolphpdude Posted July 29, 2008 Author Share Posted July 29, 2008 yeah thats what i echoed and its echooing the ID and the subject but within the same variable. Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602664 Share on other sites More sharing options...
samshel Posted July 29, 2008 Share Posted July 29, 2008 what does the line below that echo? also try to echo the query.. the explode function should seperate the 2 fields... foreach($_POST['checkbox'] as $memo) { $arr = explode(";;", $memo); echo "memo subject: ".$arr[1]." has been deleted.<br/>"; echo "DELETE FROM memo WHERE memo_id='".$arr[0]."'<br/>"; mysql_query("DELETE FROM memo WHERE memo_id='".$arr[0]."'") or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602672 Share on other sites More sharing options...
coolphpdude Posted July 29, 2008 Author Share Posted July 29, 2008 erm i give up, i'll just do another select query to get the info i need! Cheers for your help mate Link to comment https://forums.phpfreaks.com/topic/117158-passing-multiple-variables/#findComment-602834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.