php - How to run Multiple querys at the same time? -
i stuck @ point want run multiple queries cannot it.
i have code https://gyazo.com/d98f6e68c9c6d4e09620e96a29f3f910 have there 4 queries want run @ same time don't know how it, read lot of other questions on forum already. can separate them of ; signs or use mysqli_multi_query .. don't know anymore.
here printscreen of mysql db: https://gyazo.com/15ae4be5831665064b2cf8b4f703f3f3
and connection code:
define('db_host', 'localhost'); define('db_user', 'root'); define('db_pass', ''); define('db_name', 'mysql_enquete'); $db_link = mysqli_connect(db_host, db_user, db_pass, db_name) or die ("verbindingsfout"); $mysqli = new mysqli(db_host, db_user, db_pass, db_name); if (mysqli_connect_errno()) { printf("connect failed: %s\n", mysqli_connect_error()); exit(); } if ($result = $mysqli->query("select database()")) { $row = $result->fetch_row(); printf("", $row[0]); $result->close(); }
and code have dropdown menus bands
nummer 1<br/> <?php echo '<select name="bands1">'; echo '<option>kies een band</option>'; $sql="select * bands order band"; $result = mysqli_query($db_link, $sql); if (!$result){ die ("database connection failed!"); } while($row = mysqli_fetch_assoc($result)){ echo '<option value="' . $row['bandid'] . '">' . $row['band'] . '</option>'; } echo '</select>'; ?></br>
i hope can tell me how can run querys in picture
$sql = " update bands set punten = punten + 10 bandid = '".$bands1."'; update bands set punten = punten + 6 bandid = '".$bands2."'; update bands set punten = punten + 3 bandid = '".$bands3."'; insert users (id, email) values ('null','$email') ";
there's no need run queries @ once. perform each query separately. however, can combine 3 udpate
queries single query using case
expression.
so code should (i'm showing how use prepared statement instead of substituting variables).
$stmt = mysqli_prepare($db_link, " update bands set punten = case bandid when ? punten + 10 when ? punten + 6 when ? punten + 3 end bandid in (?, ?, ?)"); mysqli_stmt_bind_param($stmt, "iiiiii", $bands1, $bands2, $bands3, $bands1, $bands2, $bands3); mysqli_stmt_execute($stmt); $stmt2 = mysqli_prepare($db_link, "insert users (id, email) values (null, ?)"); mysqli_stmt_bind_param($stmt2, "s", $email); mysqli_stmt_execute($stmt2);
Comments
Post a Comment