PHPの簡単な数学で助けが必要です。私は前にこのようなことをしたことはありませんが、それを必要とする自分自身を見つける。ここに私が達成しようとしていることがあります。PHPで数学を行う
私はクラスのすべての学生のテストスコアとコメントを含む 'eval'というMySQLテーブルを持っています。
私は毎月、合計で10ポイントの4つのエリアで学生をテストし、評価します。
テーブルの行は次のようになります。
ID name participation speaking listening writing reading comment
1 John Smith Excellent 7 7 7 7 Teacher Comment.
2 Jane Brown Excellent 6 7 7 6 Teacher Comment.
3 Mike Jones Very Good 6 7 7 6 Teacher Comment.
このデータを表のページに表示します。
私がしたいのは、ページのテーブルに追加の列を作成し、PHPを使用して4つの値(話す、聞く、書く、読む)を追加し、余分なカラム。ここで
は、MySQL<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_rsEval = "-1";
if (isset($_GET['group'])) {
$colname_rsEval = $_GET['group'];
}
mysql_select_db($database_sgnesldb, $sgnesldb);
$query_rsEval = sprintf("SELECT * FROM eval WHERE `group` = %s", GetSQLValueString($colname_rsEval, "text"));
$rsEval = mysql_query($query_rsEval, $sgnesldb) or die(mysql_error());
$row_rsEval = mysql_fetch_assoc($rsEval);
$totalRows_rsEval = mysql_num_rows($rsEval);
?>
でテーブルを選択するためのコードであり、ここで私が前の列に表示する割合の合計が必要
<td width="12" align="center" valign="top"><?php echo $row_rsEval['ID']; ?></td>
<td width="145" valign="top" class="darkbrownbold"><?php echo $row_rsEval['name']; ?></td>
<td width="72" align="center" valign="top"><?php echo $row_rsEval['participation']; ?></td>
<td width="55" align="center" valign="top" class="darkbrownbold"><?php echo $row_rsEval['speaking']; ?></td>
<td width="53" align="center" valign="top" class="darkbrownbold"><?php echo $row_rsEval['listening']; ?></td>
<td width="42" align="center" valign="top" class="darkbrownbold"><?php echo $row_rsEval['writing']; ?></td>
<td width="44" align="center" valign="top" class="darkbrownbold"><?php echo $row_rsEval['reading']; ?></td>
<td width="25" align="center" valign="top"> </td>
<td width="350" valign="top"><?php echo nl2br($row_rsEval['comment']); ?></td>
<td width="45" align="center" valign="top" class="darkbrownbold"><?php echo $row_rsEval['top5']; ?></td>
ページのレイアウトのためのコードです「コメント」
ありがとうございました。
:-)クエリでescape your valuesすることを忘れないでください... – ManseUK
とSQLあまりに – ajreal
タイトルを変更してください! – TMS