0

I need some help with a php/sql program, referring checkboxes. Currently I have this:

foreach($result as $row){
  $device_serialnum = $row['device_serialnum'];
  $device_manufacturer = $row['device_manufacturer'];
  $description = $row['description'];
  echo("<input type=\"checkbox\" name = \"device_serialnum[]\" value=\"$device_serialnum\"> $device_serialnum : $device_manufacturer : $description<br/>");
}   

Where the values of device_serialnum, device_manufacturer and description come from a sql query made previously.

What I had in mind was for each checkbox have two values (device_serialnum, device_manufacturer), because they are two primary keys I need to retain in order to complete the next query.

Is there a simple way to that following the scheme of my previous code?

Thanks in advance,

Regards

Blackfing

2
  • why dont you make an array including the primary keys that you want from each row and the checkbox get an int value (1,2,3,4...) and then to return the primary keys just do something like array[checbox.value] Commented Nov 21, 2015 at 18:48
  • A super simple solution would be to put both variables in the value attribute of the check box seperate by some character(s) that will never be in either variable. Then, in the script that processes the values, explode the value on that seperator. Commented Nov 21, 2015 at 18:52

1 Answer 1

1

A checkbox may only have one value attribute. But you can put several values into that attribute by using somem kind of delimiter like "|":

echo("<input type=\"checkbox\" name = \"device_specs[]\" value=\"$device_serialnum|$device_manufacturer\"> $device_serialnum : $device_manufacturer : $description<br/>");

When processing the form values you'll have to split thos values again:

list($device_serialnum,$device_manufacturer) = explode('|',$_POST['device_specs']);

Just an idea...

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I will try that and I think that may solve my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.