samedi 27 mai 2017

multiple if statements used to update database entries

Have the following:

if ($row['college4'] == null) {
                        $sql = "UPDATE colleges SET college3 = NULL, sports3 = NULL";
                    }
                    if ($row['college3'] == null) {
                        $sql = "UPDATE colleges SET college2 = NULL, sports2 = NULL";
                    }
                    if ($row['college2'] == null) {
                        $sql = "UPDATE colleges SET college1 = NULL, sports1 = NULL";
                    }

Essentially, if a specific column in the database equals NULL, then set the preceding column to NULL. The prior coding works, however, only for the most recent if statement (In this case, college2). Once that executes, the remaining if statements are ignored (i.e. college 4 and college 3.

If more explanation is needed please let me know. I think I am just looking for a how to on having the sql queries recognize in a cascading manner. Thanks.

Aucun commentaire:

Enregistrer un commentaire