주간 추첨 시스템을 만들려고합니다. 여기 내가하고 싶습니다. 매주 cron 작업은 데이터베이스에서 임의로 사용자를 선택하는 "cron.php"를 실행합니다.하나의 PHP 파일로 여러 작업 실행
JSONAPI를 사용하여 Minecraft 서버에 항목을 제공합니다. 그 후에 그것은 메인 웹 사이트에 'gratz'또는 무엇이든을 말하는 뉴스 상태를 게시 할 것입니다. 나는이 모든 것들을 거기에서 할 수 있지만, 나는 PHP 파일 하나 하나를 가지고이 모든 것을 어떻게 할 것인지 혼란 스럽다.
<?php
//Selects a random entry from the database and gives them something in game and also says Congradulations on the website as a news post under the name "TCCraft".
$mysqli = new mysqli("localhost", "uname", "pass", "db with usernames in it");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if ($result = $mysqli->query("SELECT id, name FROM users ORDER BY RAND() LIMIT 1")) { //selects random user from the database.
$row = mysqli_fetch_array($result);
$name = $row['name']; //$name stands for the randomly selected user.
//now its time to run the code to give the player the reward. We are using JSONAPI http://dev.bukkit.org/bukkit-plugins/jsonapi/
require('JSONAPI.php');
$obj = new JSONAPI('IP', 20059, 'unam', 'pass', 535153);
$result = $obj->call("givePlayerItem", array("{$name}, 264, 24"));
$time = date("Y-m-d H:i:s");
//connect to news db
$con = mysqli_connect("localhost", "uname", "pass", "db for all the news posts");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO posts (title, user, body, date) VALUES ('Raffle Winner!','TCCraft','<p>Congradulations to {$name} for winning our weekly raffle!</p><p>If you would like to enter the raffle click <a href='http://tccraft.net/enter.php'>here</a></p>','$time')";
echo "should be added";
}
?>
내가 밖으로이 코드를 테스트하고 오류를 가지고,하지만 그것은 또한 진짜 문제는 단지 뉴스 데이터베이스에 뉴스 포스트를 추가 롤 작동하지 않았다 : 여기
는 내가 지금까지 무엇을 가지고 .
어떤 방식으로 작동하지 않았다
$res = mysqli_query($sql);
$sql="INSERT INTO ...";
후 추가 하시겠습니까? JSONAPI 호출의 오류에 대해서는 checkinf가 아닌 것 같습니다. – BarmarJSONAPI는 문제가 아닙니다. 문제는 뉴스를 데이터베이스에 추가하는 것입니다. 나는 내가 추측한다고 말해야한다. –