Skip to content
Advertisement

How to insert a value to a column where another column is equal to specific word?

I am currently working on an enrollment website for our research project. How to assign the section of a student where the course is “Computer Programming” limited to 50 per section? I currently have this but don’t know what to do:

$course= $_POST[course];
    $section= "Kindness";
        $query2 = "SELECT * from students WHERE Specialization= 'Computer Programming'";
        mysqli_query($conn,$query2);
        $row = mysql_fetch_assoc($query2);
        if($row['Specialization'] == $course){
            $query3 = "INSERT INTO students (Section) VALUES ('$section')";
            mysqli_query($conn,$query2);
        }

}

Advertisement

Answer

You can do this in the same query… but i think you problem is other.. do you can change or insert new students? if you can insert you can do like this:

INSERT INTO students (Section)
SELECT
   Section
FROM
   students 
WHERE
    Specialization= 'Computer Programming'
    /* here you can add other filters.. like rownum <= 50 (first 50 rows..)*/

But if you can change a value you can use a UPDATE..

I prefere resolve a problem in a one SQL query..

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement