1

結果のデータをテーブルに出力するクエリがあります。ifそのテーブルには、このステートメントに不可欠な2つのフィールドがあります:Max CapacityCurrent Capacity。これらは、同じテーブルのデータベースからのものです。

if私はステートメントを書きたいです:

if (Max_C == Current_C){
   echo "Sorry, course is full.";
}
else{
   $insert = mysql_query ("insert into blahblahblah... ");
}

どうすればよいですか?max_ccurrent_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!';
    }
4

2 に答える 2

1

挿入コードは次のとおりです。

    //Create query
    $qry="INSERT INTO table (column-name, another-column) VALUES ('$variable', '$valueyouwanttoinsert')";
    $result=mysql_query($qry);
    if ($result) {
    echo "Success!";
    }
    else {
    die("Query Failed");
    }
于 2012-04-29T21:24:35.317 に答える
0

次のコードを使用してそれを行うことができます。

//Create query
$qry="SELECT * FROM table WHERE column='$variable'";
$result=mysql_query($qry);

//Check whether the query was successful or not
if($result) {
    $course = mysql_fetch_assoc($result);
        $max_c = $course['max_c'];
        $current_c = $course['current_c'];
}
else {
    die("Query failed");
}
    if ($current_c == $max_c){
        echo "Sorry, the course is full!";
    }
    else {
        //MySQL Insert Code here
    }
于 2012-04-29T21:16:18.527 に答える