• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

make a select , then pass data to next pa ge

How can I write php program to take data form row that customer select
The below is my code please look at
www.kohsamui.ca/computer/install.html 




<?
for ($times=2;$times<=10;$times++) {
 $ProCost = 18000;
 $paid = 3000;
 $IntRate = 1.5;
 $InsCost = $ProCost-$paid;
 $interrest = $InsCost*$IntRate/100*$times;
 $total = $interrest+$InsCost;
 $monthPay = $total/$times;

//  <td>&nbsp;</td>
?>

 <tr align="right">
  <td><?php echo number_format($ProCost,2); ?></td>
  <td><?php echo number_format($paid,2); ?></td>
  <td><?php echo number_format($IntRate,2); ?></td>
  <td><?php echo $times; ?></td>
  <td><?php echo number_format($InsCost,2); ?></td>
  <td><?php echo number_format($interrest,2); ?></td>
  <td><?php echo number_format($total,2); ?></td>
  <td><?php echo number_format($monthPay,2); ?></td>
 </tr>

<?php
}
?>

</table>
0
teera
Asked:
teera
  • 2
  • 2
2 Solutions
 
str_kaniCommented:
By having  some hidden boxes you can get the values ......... as follows

<?
for ($times=2;$times<=10;$times++) {
 $ProCost = 18000;
 $paid = 3000;
 $IntRate = 1.5;
 $InsCost = $ProCost-$paid;
 $interrest = $InsCost*$IntRate/100*$times;
 $total = $interrest+$InsCost;
 $monthPay = $total/$times;

//  <td>&nbsp;</td>
?>

 <tr align="right">
  <td><?php echo number_format($ProCost,2); ?> <input name="procost<?php echo $times?>" value=""> <?php echo number_format($ProCost,2); ?> </td>

// other values here.........

 </tr>

<?php
}
?>

</table>



0
 
str_kaniCommented:
************ Correction  *********** missed to place the values inside "" for the value attribute...
<tr align="right">
  <td><?php echo number_format($ProCost,2); ?> <input name="procost<?php echo $times?>" value="<?php echo number_format($ProCost,2); ?>">  </td>

// other values here.........

 </tr>

Ref : http://www.kohsamui.ca/computer/install.html

Name the check boxes as I have done above, i.e generae dynamic name for check boxes.
<input type="checkbox" name="checkbox<?php echo $times?>" >

Once the user selects the options and submit, you can find the slected options from their name and select the values from the hidden boxes of the corresponding row set.

For example
if checkbox2 is checked select values from the  procost2 , paid2 ...etc
if checkbox3 is checked select values from the  procost3 , paid3 ...etc



Hope this helps.


0
 
jdpipeCommented:
I hope that the following will give you enough to go on with. I have taken out your stuff about the totals and interest etc - because I think you problem is related to the HTML form part of the problem. So here goes:

<?php

$data = array(
      array(1,2,3,4)
      ,array(2,5,6,7)
      ,array(3,7,8,9)
      ,array(4,7,8,9)
      ,array(5,7,8,9)
      ,array(6,7,8,9)
      ,array(7,7,8,9)
);

$action="select";
if(isset($_GET['action'])){
      $action=$_GET['action'];
}

switch($action){
      case "select":
            print("<h3>Select your rows</h3>");
            print("<form><input type=hidden name=action value=show><table border=1>");
            foreach($data as $i=>$row){
                  print("<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td>");
                  print("<td><input type=checkbox name=\"i[]\" value=\"$i\"></td></tr>");
            }
            print("</table><input type=submit value=\"submit\"><input type=reset value=\"clear\"></form>");
            break;

      case "show":      
            $ii=array();
            if(isset($_GET['i']) && is_array($_GET['i'])){
                  $ii=$_GET['i'];
            }

            print("<h3>Here is your data</h3>");
            if(count($ii)){
                  print("<table border=1>");
                  foreach($ii as $i){
                        print("<tr><td>".$data[$i][0]."</td><td>".$data[$i][1]."</td><td>".$data[$i][2]."</td><td>".$data[$i][3]."</td>");
                        print("</tr>");
                  }
                  print("</table>");
            }else{
                  die("No items selected");
            }
            break;
                        
      default:
            die("invalid action");
}


?>
0
 
jdpipeCommented:
Just stick that stuff into a PHP file by itself and put it on your webserver and it should work fine. I tested it.
JP
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now