Jump to content

displaying data on to another page by check box


ma5ect

Recommended Posts

hi all.

 

I have a table on my webpage, i want the user to select a check box which is assigned to a field on the table and once the user submits the form, i want that check box data to be displayed on another page...

 

 

i have got the form with the check box and data field assigned but dont know how i can get it to display onto the next page..

 

form page code:

 

<form name=orderform action="confirm-order.php">
  <table width="648" border="3" align="center">
    <tr>
      <td width="209"><div align="center" class="style12">
          <div align="center">Module name</div>
      </div></td>
      <td width="120"><div align="center" class="style12">
          <div align="center">Module ID</div>
      </div></td>
      <td width="158"><div align="center" class="style12">
          <div align="center">Credits</div>
      </div></td>
      <td width="117"><div align="center" class="style12">
          <div align="center">Completed</div>
      </div></td>
      <td width="61"><div align="center"></div></td>
    </tr>
    <?php do { ?>
    <tr>
      <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td>
      <td><div align="center"><?php echo $row_Recordset2['Module ID']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td>
      <td><input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td>
    </tr>
    <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
  </table>
  <p align="center">
    <input type=submit value="Order" />
</form>

Link to comment
Share on other sites

first you put everything in hidden fields like this with in the tags <form> (im guessing this is what you want)

<input type=hidden name="whatever" value="<?php echo $row_Recordset2['Module name']; ?>" />

 

then in the next page or function or what have you you can get the post like

$whatever = $_POST['whatever'];

 

let me know if you need anymore explination

Link to comment
Share on other sites

Try this:

<form name="orderform" action="confirm-order.php" method="post">
  <table width="648" border="3" align="center">
    <tr>
      <td width="209"><div align="center" class="style12">
          <div align="center">Module name</div>
      </div></td>
      <td width="120"><div align="center" class="style12">
          <div align="center">Module ID</div>
      </div></td>
      <td width="158"><div align="center" class="style12">
          <div align="center">Credits</div>
      </div></td>
      <td width="117"><div align="center" class="style12">
          <div align="center">Completed</div>
      </div></td>
      <td width="61"><div align="center"></div></td>
    </tr>
    <?php do { ?>
    <tr>
      <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td>
      <td><div align="center"><input type='hidden' name='module' value='<?php echo $row_Recordset2['Module ID']; ?>' /></div></td>
      <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td>
      <td><input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td>
    </tr>
    <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
  </table>
  <p align="center">
    <input type=submit value="Order" />
</form>

 

I created an input type hidden field named "module" so that $_POST[''] knows from where to get the value!

 

Link to comment
Share on other sites

As you list your data inside a table have a checkbox defined:

<input type="checkbox" name="data" />

 

Append the unique identifier onto the name of "data" (the name of the checkbox) so you have something like this:

<input type="checkbox" name="data1" />
<input type="checkbox" name="data2" />
<input type="checkbox" name="data3" />
<input type="checkbox" name="data4" />

and so-on.

 

When the user selects one or more of the checkboxes and clicks the submit button all you need do is recreate the MySQL call that generated the list and check the names:

$query=mysql_query("SELECT data FROM table");
while ($fetch=mysql_fetch_assoc($query)) {
  if ($_POST['data'.$fetch['id']]) {
    //checkbox was selected
  }
}

 

Not sure if this is the best way but it works!

Link to comment
Share on other sites

then just add an iterator to your loop:

<?php $i = 1; //initialize iterator
do { ?>
    <tr>
      <td height="22"><span class="style9"><?php echo $row_Recordset2['Module name']; ?></span></td>
      <td><div align="center"><?php echo $row_Recordset2['Module ID']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['credits']; ?></div></td>
      <td><div align="center"><?php echo $row_Recordset2['Completed']; ?></div></td>
      <td><input name="module<?php echo $i; //add iterator value to the checkbox name ?>" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" /></td>
    </tr>
    <?php ++$i; //increment iterator
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>

Link to comment
Share on other sites

I think this is where you'd do it:

<input name="module<?=$row_Recordset2['Module ID']?>" type="checkbox" id="module" value="<?=$row_Recordset2['Module name']?>" />

 

Try that and view the source of the page and see if the name of each checkbox is unique depending on the ID of each row.

Link to comment
Share on other sites

created with repeat region

 

<form name="orderform" action="confirm-order.php" method="post">
  <table width="757" border="3" align="center">
    <tr>
      <td width="133"><div align="center" class="style12">
          <div align="center">Module Name</div>
      </div></td>
      <td width="106"><div align="center" class="style12">
          <div align="center">Module ID</div>
      </div></td>
      <td width="104"><div align="center" class="style12">
          <div align="center">Credits</div>
      </div></td>
      <td width="117"><div align="center" class="style12">
          <div align="center">Completed</div>
      </div></td>
      <td width="110"><div align="center" class="style12">
        <div align="center">Attempts</div>
      </div></td>
      <td width="100"><div align="center" class="style12">
        <div align="center">Level</div>
      </div></td>
      <td width="37"><div align="center">Select</div></td>
    </tr>
    <?php do { ?>
    <tr>
      <td height="22"><span class="style13"><?php echo $row_Recordset2['Module name']; ?></span></td>
      <td><div align="center" class="style14"><?php echo $row_Recordset2['Module ID']; ?></div></td>
      <td><div align="center" class="style14"><?php echo $row_Recordset2['credits']; ?></div></td>
      <td><div align="center" class="style14"><?php echo $row_Recordset2['Completed']; ?></div></td>
      <td><div align="center" class="style14"><?php echo $row_Recordset2['Attempts']; ?></div></td>
      <td><div align="center" class="style14"><?php echo $row_Recordset2['Level']; ?></div></td>
      <td><div align="center">
        <input name="module" type="checkbox" id="module" value="<?php echo $row_Recordset2['Module name']; ?>" />
      </div></td>
    </tr>
    <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
  </table>
  <p align="center">
    <input type=submit value="Submit" />
</form>

Link to comment
Share on other sites

I prefer to use while() loops as a do() loop will always be executed at least once because the clause is encountered after the code has been run. I'm not sure what type of MySQL call you're running but is there a chance your call can return nothing? If there is, you'll be better off using while() instead.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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