144055
Apr 27, 2020
765
2
0
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
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
Please also mark the comments that contributed to the solution of the article
Content-Key: 567991
Url: https://administrator.de/contentid/567991
Printed on: April 23, 2024 at 15:04 o'clock
2 Comments
Latest comment
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
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
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
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