我有一個查詢將結果數據輸出到表中。我在該表中有兩個字段,這對if
聲明至關重要:Max Capacity
和Current Capacity
。這些來自我們的數據庫,來自同一張表。使用if語句時使用數據庫中的值
我想寫一個if
聲明:
if (Max_C == Current_C){
echo "Sorry, course is full.";
}
else{
$insert = mysql_query ("insert into blahblahblah... ");
}
我該怎麼辦呢?如何從db中指定max_c
和current_c
?
的該部分代碼:
if($courseandtime) { $max_e = $courseandtime['MaxEnrollment']; $current_e = $courseandtime['COUNT(REGISTERED.SID)']; }
if ($current_e < $max_e) {
echo "
<form action='register-exec.php' method='post'>
<label>Time: $_POST[Time]</label><br>
<input type='hidden' value='$Time' /><br><br>
<label>Student ID:</label><br>
<input type='text' name='SUCID' id='SUCID' /><br><br>
<label>CID: $_POST[CID]</label><br>
<input type='hidden' name='CID' id='CID' /><br><br>
<label>SID: $row['SID']</label><br>
<input type='hidden' name='SID' id='SID' /><br><br>
<button type='submit'>Register</button>
</form>
";
}
else {
echo 'Sorry, were full!';
}
你問該怎麼辦數據庫查詢?要麼? – 2012-04-29 21:11:34
請停止使用古老的'mysql_ *'函數編寫新代碼。他們不再被維護,社區已經開始[棄用流程](http://news.php.net/php.internals/53799)。相反,您應該瞭解[準備好的陳述](http://en.wikipedia.org/wiki/Prepared_statement)並使用[PDO](http://php.net/pdo)或[MySQLi](http:// php.net/mysql)。如果你關心學習,[這裏](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers)是一個相當不錯的PDO相關教程。 –