开发者

Get more than one line of data sent to browser

开发者 https://www.devze.com 2023-03-16 19:59 出处:网络
I have a form which transports data to another page using $_GET in PHP. In the browser on the other page, it shows all the data exported but when GET it into the page, it only shows the first line. I

I have a form which transports data to another page using $_GET in PHP. In the browser on the other page, it shows all the data exported but when GET it into the page, it only shows the first line. I also want to be able to export only selected fields.

Below is my code,

    <?php do { ?>
  <form  action="../masspay/index.php" name="pile" method="GET" >
  <tr>
    <td><input type="checkbox" name="checkbox" value="check" /></td>
    <td><input name="id" type="text" id="id" value="<?php echo $row_pile['id']; ?>" size="10" /></td>
    <td><input name="amount" type="text" id="amount" value="<?php echo $row_pile['amount']; ?>" size="10" /></td>
    <td><input name="amtnaira" type="text" id="amtnaira" value="<?php echo $row_pile['amtnaira']; ?>" size="13" /></td>
    <td><input name="acctno1" type="text" id="acctno1" value="<?php echo $row_pile['acctno1']; ?>" size="10" />
      (<?php echo $row_pile['accountname']; ?>)</td>
    <td><input name="phone" type="text" id="phone" value="<?php echo $row_pile['phone']; ?>" size="13" /></td>
    <td><input name="staff" type="text" id="staff" value="<?php echo $row_admin['name']; ?>" size="15" /></td>
    <tr>
          <?php } while ($row_pile = mysql_fetch_assoc($pile)); ?>
         <td colspan="7"><input type="submit" name="Submit" value="Process Selected" /></td>
  &l开发者_JAVA技巧t;/tr>
  </form>


kk its looks like you have a database from where you are fetching the values and displaying it into values of text box.For sending the values you have to catch them on the index.php page by doing

$_GET['id']
$_GET['name'] and furthor
 now for selected field set the value on the other page check the value of checkbox that it is checked or unchecked by assinging a variable


Why are you sending data like this? a session might be a better choice.

Anyway if the sql has more than one result the previous _GET values will be overwritten.

Try this:

  <?php do { ?>
  <form  action="../masspay/index.php" name="pile" method="GET" >
  <tr>
    <td><input type="checkbox" name="checkbox[]" value="check" /></td>
    <td><input name="id[]" type="text" id="id" value="<?php echo $row_pile['id']; ?>" size="10" /></td>
    <td><input name="amount[]" type="text" id="amount" value="<?php echo $row_pile['amount']; ?>" size="10" /></td>
    <td><input name="amtnaira[]" type="text" id="amtnaira" value="<?php echo $row_pile['amtnaira']; ?>" size="13" /></td>
    <td><input name="acctno1[]" type="text" id="acctno1" value="<?php echo $row_pile['acctno1']; ?>" size="10" />
      (<?php echo $row_pile['accountname']; ?>)</td>
    <td><input name="phone[]" type="text" id="phone" value="<?php echo $row_pile['phone']; ?>" size="13" /></td>
    <td><input name="staff[]" type="text" id="staff" value="<?php echo $row_admin['name']; ?>" size="15" /></td>
    <tr>
          <?php } while ($row_pile = mysql_fetch_assoc($pile)); ?>
         <td colspan="7"><input type="submit" name="Submit" value="Process Selected" /></td>
  </tr>
  </form>

The results of $_GET['id'], $_GET['amount'], etc will now be an array and contain all the sql results.

Since I don't know what you are doing on the receiving page I'm using print_r so that you can see the structure of the data:

echo '<pre>'; // easier to read in a browser

echo 'Dump of checkbox: <br/>';
print_r($_GET['checkbox']);

echo 'Dump of id: <br/>';
print_r($_GET['id']);

echo 'Dump of amount: <br/>';
print_r($_GET['amount']);

echo 'Dump of acctno1: <br/>';
print_r($_GET['acctno1']);

etc ...

echo '</pre>';

The example output:

Dump of checkbox:
array(
    0 => 'check', // id 1 has been checked
    1 => '',      // id 2 has not been checked
),


Dump of id:
 array(
    0 => 1, // id 1
    1 => 2, // id 2
  ),


Dump of amount:
  array(
    0 => amount for id 1,
    1 => amount for id 2,
  )


Dump of acctno1:
  array(
    0 => acctno1 for id 1
    1 => acctno1 for id 2
  )

  etc ...

To check if the checkbox has be ticked:

// will return checked
if ($_GET['checkbox'][0] == 'check') {
    echo 'checked';
} else {
    echo 'not checked';
}

//will return not checked
if ($_GET['checkbox'][3] == 'check') {
    echo 'checked';
} else {
    echo 'not checked';
}

Update for comment:

$tt = ''.
foreach ($_GET['id'] as $key => $id) {
    $tt .= "$_GET['acctno1'][$key], $_GET['amount'][$key], not-private, order #$id. www.xxx.com, we hope to serve you often.<br/>";
}

echo $tt;


Since you only need to select which results to show on the receiving page this is a better and safer way of doing it:

  <form  action="../masspay/index.php" name="pile" method="GET" >
   <tr>
    <?php while ($row_pile = mysql_fetch_assoc($pile)) { ?>
     <td><input type="checkbox" name="checked[]" value="<?php echo $row_pile['id']; ?>" /></td>
     <td><?php echo $row_pile['id']; ?></td>
     <td><?php echo $row_pile['amount']; ?></td>
     <td><?php echo $row_pile['amtnaira']; ?></td>
     <td><?php echo $row_pile['acctno1']; ?>(<?php echo $row_pile['accountname']; ?>)</td>
     <td><?php echo $row_pile['phone']; ?>></td>
     <td><?php echo $row_admin['name']; ?></td>
     <?php } ?>
     <td colspan="7"><input type="submit" name="Submit" value="Process Selected" /></td>
   </tr>
  </form>

On the receiving page:

if (empty($_GET['checked']) {
    echo 'No results';
} else {

    $ids = array();
    foreach ($_GET['checked'] as $checked) {
        settype($checked, 'integer');
        $ids[] = "id = $id";
    }

    //Modify the sql used for the form to add this WHERE:
    $sql = 'SELECT * FROM table WHERE ' . implode(' OR ', $ids);

    $pile = mysql_query($sql);

    while ($row_pile = mysql_fetch_assoc($pile)) { 
        echo "$row_pile['acctno1'] $row_pile['amount'], not-private, order #$row_pile['id'];. www.xxx.com, we hope to serve you often.<br/>";
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号