Jump to content

Passing multiple variable's


coolphpdude

Recommended Posts

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

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??

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..

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.

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());
  }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.