144055
Goto Top

Erstellen einer Zufallszahl per PHP-Script

Hallo.

Ich führe jede Nacht um 00:01 Uhr folgendes Scipt aus:

<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";

Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "UPDATE users SET online_day = 1 WHERE ID BETWEEN 10000 AND 14999";

if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}

mysqli_close($conn);
?>

Wie muss ich das Script abändern, dass bei "SET online_day = 1" anstelle von 1 eine Zufallszahl zwischen 1 und 7 erstellt wird?

Vielen Dank für Hilfe, denn ich komme einfach nicht weiter.

Gruß
Tom

Content-Key: 567991

Url: https://administrator.de/contentid/567991

Printed on: April 23, 2024 at 15:04 o'clock

Member: falscher-sperrstatus
falscher-sperrstatus Apr 27, 2020 at 08:37:42 (UTC)
Goto Top
Hallo Tom,

bitte durchsuch doch am besten mal die PHP Datenbank: https://www.php.net/manual/de/function.rand.php

Bsp.

Ansonsten steht das auch hier im Board schon oft genug.

Grüße,

Christian
certifiedit.net
Member: MadMax
MadMax Apr 27, 2020 at 11:29:30 (UTC)
Goto Top
Moin,

ich würde das nicht mit PHP lösen, sondern direkt im SQL. Wie das geht, findest Du hier:
https://dev.mysql.com/doc/refman/8.0/en/mathematical-functions.html#func ...

Gruß, Mad Max