1

I am trying to build a system to compare two records in the database. Where the records will be displayed in Ascending order of the name column and then i can choose 2 records by marking checkbox along the side of these records and then click compare. When i click compare i want to send the id of these two records to the next page.

When i use Get method i get {id}=on${id}=on. what i want to do is $id1 ={id}&$id2={id}

not sure how to do this ? do u i need to use javascript ?

3 Answers 3

2

Give the checkbox the value you want - i.e. the id instead of "on".

<input type="checkbox" name="id" value="on" /> submits as id=on if checked.

<input type="checkbox" name="id" value="1337" /> submits as id=1337 if checked.

Unchecked checkbox are not submitted at all, so you have to check if(isset($_GET['id']))


And, as you seem to be using multiple ids:

<input type="checkbox" name="id[]" value="1337" />
<input type="checkbox" name="id[]" value="42" />

This will create an array $_GET['id'] containing the values of the checked ids, e.g. array(1337, 42) if both checkboxes were checked.

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

Comments

2

very very confused by your question, please clear it up.

For what i can make out are you not wanting to do:

$ids = isset($_GET['ids']) && is_array($_GET['ids']) ? $_GET['ids'] : false;

if($ids)
{
    //Check the database
}

and then HTML Wise

<form method="get" action="index.php">
    <input type="checkbox" name="ids[]" value="1" />
    <input type="checkbox" name="ids[]" value="12" />
    <input type="checkbox" name="ids[]" value="123" />
    <input type="checkbox" name="ids[]" value="1234"/>
    <input type="checkbox" name="ids[]" value="2" />
    <input type="checkbox" name="ids[]" value="23" />
    <input type="checkbox" name="ids[]" value="234"/>
</form>

this will produce checkboxes and on server side you can use $ids

1 Comment

ThiefMaster got my question of what i want. Thanks for the answer, sorry to confuse you :)
1

I think should be this instead:

<input type="checkbox" name="id1" value="<?=$ID1?>" />
<input type="checkbox" name="id2" value="<?=$ID2?>" />

You need to give unique ID for two different checkbox
if you want to do comparison in subsequent page

4 Comments

but i have around 200 odd records but will be comparing only two of them.
but will be comparing only two of them.
@Harsha MV - Use radio button instead. So in the end, only two GET will be set, and user only can select one for each id
@Harsha MV - Yup, this is based on your description. If you need to compare multiple records to multiple records, probably you would need to refine your question again, and preferable with your HTML form

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.