-4

Ive been searching alot lately but couldnt come up for a solution about this problem of looping...
i am currently workin on a page that would display transactions from database and would let you pay using a button.

i made a table and put a button in the last column of every row using while($row = mysql_fetch_array($query)).
i made use of isset that everytime the button is clicked some session will store corresponding to the values of the row...but the problem is whichever button i clicked whether its in the first, second, or third row the values that i get comes from the last row.

Is there a way to get the value of the variables of each row? here are the codes:

    $qry1=mysql_query("SELECT * FROM request WHERE client_id ='".$_SESSION['client_id']."'");
                $check = mysql_num_rows($qry1);
 if ($check == 0) {  echo "There are no recent transactions to display.";  }
else{


                $table = "<table align= 'center' border='1' bordercolor='#ccc' cellpadding='20'>";
                $table .= "<tr><th>REQUEST #</th><th>DATE</th><th>TIME</th><th>EVENT</th><th>PRICE</th><th>STATUS</th><th></th></tr>";

                while($row = mysql_fetch_array($query)){
                                print_r($row);
                $rid = $row['request_id'];
                $reid = $row['event_id'];
                $raid = $row['addons_id'];
                $reprice = $row['request_price'];
                $redate = $row['event_date'];
                $retime = $row['event_time'];
                $restatus = $row['event_status'];


                if($reid==1 || $reid==2 || $reid==3){
                $debut="Standard Debut";

                }
                else { $debut="Kids Party";
                }

            $table .= "<tr><td align = center># ".$rid."</td><td>".$redate."</td><td>".$retime."</td><td align= center>".$debut."</td><td align=center>P".$reprice.".00</td><td align=center>".$restatus."</td>";
                if($restatus=='PENDING')
                {
                $table .= "<td align=center>";
                $table .= "<form method='post'>";

                $table .= "<input type='submit' name='btnSubmit' id='btnSubmit' value='Pay' tabindex='0' />        
                </form>
                </td>";
                include "../pages/my_reqsubmit.php";
                }
                else
                {
                    $table .= "<td align=center>--</td>";
                }   

     $table .= "</tr>";



     }

            $table .= "</table>";                   




                echo $table;

code for my_reqsubmit.php :

    if(isset($_POST["btnSubmit"]))
 {
 include("../pages/config.php");    
 $URL= "../request/view.php";
 $_SESSION['RequestUser']="asd";
 $_SESSION['dtRequest'] = $redate;  
 $_SESSION['tmRequest'] = $retime;
 $_SESSION['etype'] = $debut;
 $_SESSION['addons_id'] = $raid;


if($reid==1){
$_SESSION['epack']= "Package A";
}
else if($reid==2){
$_SESSION['epack']= "Package B";
}
else if($reid==3){
$_SESSION['epack']= "Package C";
}
else if($reid==4){
$_SESSION['epack']= "Package A";
}
else if($reid==5){
$_SESSION['epack']= "Package B";
}
else if($reid==6){
$_SESSION['epack']= "Package C";
}


                $qrry2 = mysql_query("SELECT * FROM addons WHERE addons_id =$raid");
                while($row = mysql_fetch_array($qrry2)){
$_SESSION['pservice'] = $row['addons_ps'];
$_SESSION['pbooth'] = $row['addons_pb'];
$_SESSION['mbar'] = $row['addons_mb'];  
$_SESSION['phprice'] = 3500;
$_SESSION['pbprice'] = 5000;
$_SESSION['mbprice'] = 11000;
}
    $qrry3 = mysql_query("SELECT * FROM event WHERE event_id =$reid");
    while($row = mysql_fetch_array($qrry3)){
$_SESSION['eprice'] = $row['event_price'];
            }

$_SESSION['price'] = $reprice;

header ("Location: $URL"); 
   }
       ?>

Please help me...id really appreciate it!

rbyrby
  • 1
  • 2
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). *They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation)*. See the [red box](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which. – Jay Blanchard Oct 06 '14 at 13:40
  • our button does not seem to post any reference to the row it was in. How should your backend know which transaction was to be changed? – ToBe Oct 06 '14 at 13:42
  • @ToBe you are right! pardon me i am totally a beginner with programming could u recommend any method that i can make use of? – rbyrby Oct 06 '14 at 13:50
  • add a hidden variable in your form and use that. `echo "";` – ToBe Oct 06 '14 at 13:53
  • @ToBe thank you it worked! i made each variable a hidden input. – rbyrby Oct 06 '14 at 16:05

1 Answers1

0

You need to include SOMETHING in your button to link that row's button with the matching DB record. I'll use <a> tags instead, but the EXACT same concept is used for buttons:

<a href="viewrecord.php?id=1">Click here for record #1</a>
                           ^---the ID of the record that this button/link would use
<a href="viewrecord.php?id=2">Click here for record #2</a>
<a href="viewrecord.php?id=3">Click here for record #3</a>
Marc B
  • 356,200
  • 43
  • 426
  • 500