我最近一直在搜索很多,但无法找到关于循环问题的解决方案...
我目前在一个页面上工作,该页面将显示数据库中的交易,并允许您使用按钮付款。
我创建了一个表,并使用while($ row = mysql_fetch_array($ query))在每行的最后一列放置一个按钮。
我使用了isset,每次单击按钮时,某些会话将存储对应于行的值...但问题是我点击的任何一个按钮,无论它在第一行,第二行还是第三行,我得到的值都来了从最后一行开始。
有没有办法获得每行变量的值?这是代码:
$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;
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");
}
?>
请帮帮我......我真的很感激!
答案 0 :(得分:0)
您需要在按钮中包含SOMETHING,以将该行的按钮与匹配的DB记录相关联。我将使用<a>
标签,但EXACT相同的概念用于按钮:
<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>