我有table player_points,其中包含player_name,run,sixes,match_no,fiftys,数百,point_scored。
我使用以上字段制作表单,其中我插入运行和六个并使用运行和计算来计算fiftys,数百和point_scored六,在三六之后每六十分给予额外的10分。 它工作正常,但当我插入运行和六和保存它只显示计算在五十,百和点得分的文本框没有保存到数据库表。我第二次保存后保存到数据库中。我的代码如下:
<tr><td colspan="9"><hr style="border:1px #999 dashed;"></td></tr>
<tr>
<th>Player</th>
<th>Status</th>
<th>Runs</th>
<th>6's</th>
<th>50's</th>
<th>100's</th>
<th>TP</th>
<th>Action</th>
</tr>
<tr><td colspan="9"><hr style="border:1px #999 dashed;"></td></tr>
<?php
$classObj->getPlayerPointTable();
//$matchid = $_GET['mid'];
$condpl = "player_name='".$player1."' AND match_no = '".$matchid."'";
$resultpl = $classObj->selectSql($condpl);
//$recordcount = $classObj->getAffectedRows($result);
$rowpl = $classObj->fetchData($resultpl);
foreach($rowpl as $rowspl)
{
$Status1 = $rowspl['status'];
$runs1 = $rowspl['run_scored'];
$sixes1 = $rowspl['sixs'];
$fifty1 = $rowspl['fifty'];
$hundred1 = $rowspl['hundred'];
$total_score1 = $rowspl['Total_Score'];
$total_points1 = $rowspl['point_scored'];
$firstPoint1 = $rowspl['FirstPoint'];
$allocation1 = $rowspl['allocation'];
}
?>
<?php
$bonus1 = 10;
$bonus2 = 20;
$bonus3 = 25;
$bonus4 = 50;
/*condition for fifty 0 & 1 start */
if ($runs1 >= 50 && $runs1 <= 99 || $runs1 >= 150 && $runs1 <= 199 || $runs1 >= 250 && $runs1 <= 299) {
$fifty1 = 1;
} else {
$fifty1 = 0;
}
if ($runs1 >= 50 && $runs1 <= 499) {
$tfif1 = $runs1 + $bonus3;
} else {
$tpor1 = $runs1;
}
/*condition for fifty 0 & 1 end */
/*condition for hundred 0 & 1 start */
if ($runs1 >= 100 && $runs1 <= 199) {
$hundred1 = 1;
}
else if ($runs1 >= 200 && $runs1 <= 299) {
$hundred1 = 2;
}
else {
$hundred1 = 0;
}
/*condition for hundred 0 & 1 end */
/*Condition start for Six excess to 3 sixes*/
$i1 = $sixes1 - 3;
if($i1 >= 1 && $i1 <= 500)
{
$tsix1 = $i1 * $bonus1;
}
else
{
$tsix1 == 0;
}
/*Condition start for Six excess to 3 sixes*/
if($fifty1 == 1 && $hundred1 >= 1)
{
$tsixhnrd1 += $bonus4;
}
/*condition for hundred 0 & 1 end */
if ($runs1 >= 100 && $runs1 <= 500) {
$trun1 += $bonus3;
}
$total_points1 = $tfif1+$tsix1+$tsixhnrd1+$trun1+$tpor1;
$total_score1 = $runs1;
/*veriable for Balling team database insertions end*/
?>
<form enctype="multipart/form-data" method="post" name="formA1">
<tr>
<td><div style="width:auto;padding-left:7px;font-size:17px;"><?php echo $player1;?></div>
<input type="hidden" name="player1" id="player1" value="<?php echo $player1;?>" />
<input type="hidden" name="matchid" id="matchid" value="<?php echo $matchid;?>" />
</td>
<?php
if($Status1=='P'){
?>
<td align="center">
<select id='status1' name='status1' onChange="dis_ableA1(this)">
<option value='NP'>NP</option>
<option value='P' selected>P</option>
<option value='O'>Out</option>
</select>
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;background:#f5c0c0;" name="runs1" id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;background:#f5c0c0;" name="sixes1" id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
</td>
<?php
} else if($Status1=='O'){
?>
<td align="center">
<select id='status1' style="width:50px;height:25px;" name='status1' onChange="dis_ableA1(this)">
<option value='NP'>NP</option>
<option value='P'>P</option>
<option value='O' selected>Out</option>
</select>
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;background:#ccc;" disabled name="runs1" id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;background:#CCC;" disabled name="sixes1" id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
</td>
<?php } else { ?>
<td align="center">
<select id='status1' style="width:50px;height:25px;" name='status1' onChange="dis_ableA1(this)" tabindex="1">
<option value='NP'>NP</option>
<option value='P'>P</option>
<option value='O'>Out</option>
</select>
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:50px;height:25px;text-align:right;" name="runs1" disabled id="runs1" value="<?php echo $runs1;?>" size="3" maxlength="3" />
</td>
<td align="center">
<input type="text" onkeypress="return blockNonNumbers(this, event, false, false);" style="width:30px;height:25px;text-align:right;" name="sixes1" disabled id="sixes1" value="<?php echo $sixes1;?>" size="2" maxlength="2" />
</td>
<?php }?>
<td align="center">
<label style="width:30px;height:25px;text-align:right;"><?php echo $fifty1;?></label>
<input style="width:30px;height:25px;text-align:right;" type="hidden" id="fifty1" name="fifty1" value="<?php echo $fifty1;?>" size='2' maxlength='2' />
</td>
<td align="center">
<label style="width:30px;height:25px;text-align:right;"><?php echo $hundred1;?></label>
<input style="width:30px;height:25px;text-align:right;" type="hidden" id="hundred1" name="hundred1" value="<?php echo $hundred1;?>" size='2' maxlength='2' />
</td>
<td align="center">
<label style="width:30px;height:25px;text-align:right;"><?php echo $total_points1;?></label>
<input style="width:30px;height:25px;text-align:right;" type="hidden" id="total_points1" name="total_points1" value="<?php echo $total_points1;?>" size='5' maxlength='5' />
<input type="hidden" name="allocation1" id="allocation1" value="pending" />
</td>
<?php
if($Status1=='P'){
?>
<td align="center">
<input type="submit" name="submitA1" id="submitA1" value="Save" />
</td>
<?php } else { ?>
<td align="center">
<input type="submit" disabled="disabled" name="submitA1" id="submitA1" value="Save" />
</td>
<?php } ?>
</tr>
</form>
<tr><td style="height:5px"></td></tr>
<!-- Insert Code Starts Submit1-->
<?php
if(isset($_POST['submitA1']))
{
$classObj->getPlayerPointTable();
$matchid = $_GET['mid'];
$cond = "player_name='".$player1."' AND match_no = '".$matchid."'";
$result = $classObj->selectSql($cond);
$count = $classObj->getAffectedRows($result);
//echo $count;
if($count > 0)
{
$player1up['status'] = $postedData['status1'];
//$player1up['player_name'] = $postedData['player1'];
$player1up['run_scored'] = $postedData['runs1'];
$player1up['sixs'] = $postedData['sixes1'];
$player1up['fifty'] = $postedData['fifty1'];
$player1up['hundred'] = $postedData['hundred1'];
$player1up['Total_Score'] = $postedData['total_score1'];
$player1up['point_scored'] = $postedData['total_points1'];
$player1up['allocation'] = $postedData['allocation1'];
$player1up['FirstPoint'] = $postedData['total_points1'];
$classObj->getPlayerPointTable();
$classObj->userPostedData = $player1up;
$cond = "match_no= '".$matchid."' AND player_name='".$player1."'";
$insert_query = $classObj->updateData($cond);
echo "<script> alert ('Player 1 update successfully.')</script>";
echo "<script>window.location='FirstIn.php?mid=$matchid'</script>";
}
else if($count <= 0)
{
$player['player_name'] = $postedData['player1'];
$player['match_no'] = $postedData['matchid'];
$player['status'] = $postedData['status1'];
$player['run_scored'] = $postedData['runs1'];
$player['sixs'] = $postedData['sixes1'];
$player['fifty'] = $postedData['fifty1'];
$player['hundred'] = $postedData['hundred1'];
$player['Total_Score'] = $postedData['total_score1'];
$player['point_scored'] = $postedData['total_points1'];
$player['FirstPoint'] = $postedData['total_points1'];
$classObj->userPostedData = $player;
$insert_query = $classObj->insertData();
if($insert_query == 'success')
{
echo "<script> alert('Player 1 score added.')</script>";
echo "<script>window.location='score.php?mid=$matchid'</script>";
}
}
else
{
echo "<script> alert ('Error Occured')</script>";
}
}
?>
答案 0 :(得分:1)
假设您的类'getAffectedRows()
方法确实从最后一个语句中提取受影响的行,必须注意SELECT不会设置它,它将为零。
如果您想知道选择了多少行,请使用类似mysqli_num_rows的内容。