Jump to content

Recommended Posts

Hello All,

 

I am working on bringing up a list of users and have a checkbox attached to the user id.

 

What I want to do is let an admin go through the list and check as many users as they want and then when they submit the form have it pull up the information of the selected users.

 

The issue i am having is that the script only brings up one user and nothing else.

 

Form Code

<form action="home.php" method="POST">
<?php
//this pulls all members and characters to add build to their character.
$chid = $_SESSION['chapter_id'];
$query = "SELECT * FROM demographics, id where id.id = demographics.id AND id.chid='$chid' AND id.accesslvl='player' ORDER BY demographics.lastname, demographics.firstname";
$result = mysql_query($query) or die (mysql_error());
echo "<table border='1' cellspacing='15'>";
echo "<tr><td colspan='12'><hr></td></tr>";
echo "<tr><td></td><td>Players Name</td><td>Character Name</td></tr>";
while ($row = mysql_fetch_array($result))
{
extract($row);
$pname= getplayersname($id);
$query1 = "SELECT * FROM characters where id = '$id'";
$result1 = mysql_query($query1) or die ("Couldn't execute query 36.");
while ($row1 = mysql_fetch_array($result1))
{
extract($row1);
$cname= getcharname($cid);
echo "<tr><td><input type='checkbox' name='cid_$cid' /></td><td>$pname</td><td>$cname</td></tr>\n";
}
echo "<tr><td colspan='12'><hr></td></tr>\n";
}
echo "</table>\n";
?>
<input type="hidden" name="action" value="apmcharsheet">
<input type="submit" value="Print Multiple Character Sheets" name="esubmit">
</form>

 

As the code shows it limits the results to the specific group and if the user is listed as a "player".  This works with no issues.

 

Result script

$query = "SELECT * FROM characters";
$result = mysql_query($query) or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
extract($row);
$cid = $row['cid'];
if ($_REQUEST['cid_' . $cid] != '')
{
include ("charsheet.php");
//echo "<p style='page-break-before: always'>"; - commented out to test main objective
}
}

 

When I pass the info as I stated above I only get one result. The code above is the original script I tried. I thought if I changed variables or tried to change the "REQUEST" up it might work but nothing it still just pulls up 1 user.

 

Also looking at this script I added the page break as I wanted to have the info separated to separate pages if the admin wanted to print out the info.

 

So what I am looking for is a few things.

 

1) help in pointing me in the right direction.

2) Figuring out how to get multiple requests to process and show up instead of just 1.

3) Figuring out how to get the results to open in a new window not the main window.

4) making sure the page break works.

 

Any suggestions or help is appreciated. Any advice on what I can try or a mistake I made would be appreciated.

 

Thanks

Bill

Link to comment
https://forums.phpfreaks.com/topic/184458-using-checkbox-to-get-multiple-results/
Share on other sites

There is a much easier way to do this. instead of dynamically creating slightly different names (IE cid_1, cid_3) just make the checkboxes an HTML array

<input type='checkbox' name='cid[]' />
<input type='checkbox' name='cid[]' />

 

The [] part makes it an array. In the form processing code the $_POST['cid'] variable will be an array, so you can simply loop through it

foreach($_POST['cid'] as $cid){
//do whatever

ok I am a bit confused but then again I am still trying to figure this out..

 

If I am posting an array as this bit of code shows.

foreach($_POST['cid'] as $cid){
//do whatever

 

If I understand it correctly wouldn't the foreach loop through all the values in the array or would I need to right another loop.  I can see how this would work but for some reason I just can't grasp how to make sure the id is passed so the include file has access to it and can preform its query..  Also I have tried this code and get 

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

I know I am missing something simple but just cant see it right now...

 

Anyway thanks for the suggestion and any other advice you could provide would be appreciated.

 

Thanks

Bill

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.