note 128635 added to function.array-push

From: Date: Mon, 26 Jun 2023 04:16:20 +0000
Subject: note 128635 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-220595@lists.php.net to get a copy of this message
// Verbindung zur Datenbank herstellen $servername = "localhost"; $username = "root"; $password = ""; $dbname = "meinedatenbank"; $connection = mysqli_connect($servername, $username, $password, $dbname); // Überprüfen ob Verbindung erfolgreich if (!$connection) { die("Connection failed: " . mysqli_connect_error()); } $würfeln= array(); if(isset($_REQUEST["submit-button"])){ for($i=0;$i<5;$i++){ $würfe=rand(1,6); array_push($würfeln, $würfe); } echo(implode(" ",$würfeln)."<br>"); // in datenbank packen $result = true; $test = compareWürfe($connection); foreach($test as $r){ sort($r); echo(implode(" ", $r,)."<br>"); if($r == $würfeln){ $result = false; } } if($result){ savewürfe($connection, $würfeln); } if($result == false){ echo("vorhanden."); } } function savewürfe($db, $würfeln) { $stmt = $db->prepare("INSERT INTO würfe(w1, w2, w3, w4, w5) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("iiiii", ...$würfeln); $stmt->execute(); } function compareWürfe($db){ $stmt = $db->query("SELECT w1, w2, w3, w4, w5 FROM würfe ORDER BY w1 ASC, w2 ASC, w3 ASC, w4 ASC, w5 ASC"); if($stmt->num_rows > 0){ $rows = $stmt->fetch_all(); return $rows; } } function fakultaetRek($n) { if ($n <= 1) return $n; return $n * fakultaetRek($n-1); } ?> <?= fakultaetRek(5);?><br> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 79.195.18.142) ---- Manual Page -- https://php.net/manual/en/function.array-push.php Edit -- https://main.php.net/note/edit/128635 Del: integrated -- https://main.php.net/note/delete/128635/integrated Del: useless -- https://main.php.net/note/delete/128635/useless Del: bad code -- https://main.php.net/note/delete/128635/bad+code Del: spam -- https://main.php.net/note/delete/128635/spam Del: non-english -- https://main.php.net/note/delete/128635/non-english Del: in docs -- https://main.php.net/note/delete/128635/in+docs Del: other reasons-- https://main.php.net/note/delete/128635 Reject -- https://main.php.net/note/reject/128635 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220595) next »