再回来。这个网站太棒了!
我有这个PHP:
case 141:
if (isset($_GET['SubmitR'])) {
$cred = $row['chCred'] - ($_GET['Price'] * $_GET['Cnt']);
if ($cred >= 0) {
$query = "UPDATE chars SET chCred = ".$cred." WHERE chNum = ".$_SESSION['chNum'];
$result = mysql_query($query, $_SESSION['connect']) or die(mysql_error());
$query = "SELECT * FROM pack WHERE pNum = ".$_GET['Pnum']." AND pChar = ".$_SESSION['chNum'];
$result = mysql_query($query, $_SESSION['connect']) or die(mysql_error());
$row = mysql_fetch_array($result);
$cnt = $row['pCnt'] - $_GET['Cnt'];
if ($cnt <= 0) {
$query = "DELETE FROM pack WHERE pNum = ".$_GET['Pnum']." AND pChar = ".$_SESSION['chNum'];
mysql_query($query, $_SESSION['connect']) or die(mysql_error());
}
else {
$query = "UPDATE pack SET pCnt = ".$cnt." WHERE pNum = ".$_GET['Pnum']." AND pChar = ".$_SESSION['chNum'];
mysql_query($query, $_SESSION['connect']) or die(mysql_error());
}
$query = "SELECT * FROM pack WHERE pItem = ".$row['pItem']." AND pStr = ".$row['pStr']." AND pSpd = ".$row['pSpd']." AND pDur = ".$row['pDur']." AND pChar = ".$_SESSION['chNum'];
$result2 = mysql_query($query, $_SESSION['connect']) or die(mysql_error());
$row2 = mysql_fetch_array($result2) or die(mysql_error());
if (mysql_num_rows($result2) > 0) {
$cnt = $row2['pCnt'] + $_GET['Cnt'];
$query = "UPDATE pack SET pCnt = ".$cnt." WHERE pNum = ".$row2['pNum']." AND pChar = ".$_SESSION['chNum'];
mysql_query($query, $_SESSION['connect']) or die(mysql_error());
}
else {
$maxNo = 0;
$query = "SELECT MAX(pNum) FROM pack WHERE pChar = ".$_SESSION['chNum'];
$result3 = mysql_query($query, $_SESSION['connect']) or die(mysql_error());
if (mysql_num_rows($result3) > 0) {
$row3 = mysql_fetch_row($result1);
$maxNo = $row3[0] + 1;
$query = "INSERT INTO pack VALUES (".$_SESSION['chNum'].",".$maxNo.",".$row['pItem'].",".$_GET['Cnt'].",".$row['pStr'].",".$row['pMaxDur'].",".$row['pSpd'].",".$row['pMaxDur'].",1)";
mysql_query($query, $_SESSION['connect']) or die(mysql_error());
}
else {
$maxNo = $maxNo + 1;
$query = "INSERT INTO pack VALUES (".$_SESSION['chNum'].",".$maxNo.",".$row['pItem'].",".$_GET['Cnt'].",".$row['pStr'].",".$row['pMaxDur'].",".$row['pSpd'].",".$row['pMaxDur'].",1)";
mysql_query($query, $_SESSION['connect']) or die(mysql_error());
}
}
}
else {
$sColor = "#cc0000";
$sMsg = "Come with enough creds or pick a cheaper repair";
msgOut($_SESSION['connect'],$_SESSION['chNum'],$sMsg,$sColor);
}
}
//
echo "<div style='text-align:center; border-style:none;'>";
echo "<h3 style='color:#ffff00'>Repairs</h3>";
echo "<table>";
echo "<tr>";
echo "<td style='color:#ffff00'>Pack Item</td><td>Cnt</td><td>Dur</td><td>Cost</td><td>Nbr</td><td>Sel</td>";
$query = "SELECT * FROM pack WHERE pDur < pMaxDur AND pChar = ".$_SESSION['chNum']." ORDER BY pDur DESC";
$result = mysql_query($query, $_SESSION['connect']) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$query = "SELECT iDesc FROM item WHERE item = ".$row['pItem'];
$result1 = mysql_query($query, $_SESSION['connect']) or die(mysql_error());
$row1 = mysql_fetch_array($result1);
$cost = ($row['pMaxDur'] - $row['pDur']) * 10;
if ($cost < 0) {
$cost = 0;
}
echo "</tr><tr>";
echo "<td>".$row1['iDesc']."</td><td>".$row['pCnt']."</td><td>".$row['pDur']."</td><td id='repairCost".$row['pNum']."' style='color:lightgreen'>".$cost."</td>";
echo "<td>";
echo "<select name='repair".$row['pNum']."' id='repair".$row['pNum']."' size='1' style='width: 60px;' onchange='repairCnt(".$cost.",".$row['pNum'].");'>";
for ($i = 1; $i <= $row['pCnt']; $i++) {
echo "<option";
echo " value=".$i.">".$i;
}
echo "</select>";
echo "</td>";
echo "<td><input style='border-style:none;' type='radio' onclick='repair(".$_GET['Nbr'].",".$_GET['Strt'].",".$_GET['Bar'].",".$row['pNum'].")' /></td>";
}
echo "</tr>";
echo "</table>";
echo "</div>";
break;
这个JS:
//
function repair(nbr,strt,bar,pnum) {
var id = "repair"+pnum;
var e = $(id);
var t = e.options[e.selectedIndex].value;
id = "repairCost"+pnum;
var params = "Nbr="+nbr;
params += "&Strt="+strt;
params += "&Bar="+bar;
params += "&Price="+$(id).innerHTML;
params += "&Pnum="+pnum;
params += "&Cnt="+t;
params += "&SubmitR=1";
params += "&sub08=showBackroom";
alert(params);
new Ajax.Updater('div08', 'php/div08.php', {method: 'get', parameters: params, onComplete: showPackB});
}
//
function repairCnt(cost,pnum) {
var id = "repair"+pnum;
var e = $(id);
var t = e.options[e.selectedIndex].value;
var id = "repairCost"+pnum;
$(id).innerHTML = cost * t;
new Ajax.Updater('div08', 'php/div08.php', {method: 'get', parameters: params, onComplete: showStats});
}
当我用Pnum = 4,$ row ['pNum'] = 4,Cnt = 2和$ row ['pCnt'] = 4运行它时,它应该使用$ row更新记录['pCnt'] =没有什么变化。当我用Pnum = 4,$ row ['pNum'] = 4,Cnt = 4和$ row ['pCnt'] = 4运行它时,它应该删除记录并插入一个带有新值的新记录。该记录将被删除,但新记录不会被插入。