本文整理汇总了PHP中event::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP event::insert方法的具体用法?PHP event::insert怎么用?PHP event::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类event
的用法示例。
在下文中一共展示了event::insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: printf
if ($game_i[5] == "passing") {
$fn = $game_i[6];
$ln = $game_i[7];
$tn = $game_i[2];
$passToPlayer = $conn->query("select player_id from Player where first_name = '{$fn}' && last_name = '{$ln}' && team_name = '{$tn}' ");
if ($passToPlayer->num_rows == 0) {
printf("Error: No passingTO player found!");
exit;
}
$cnt["passTo"] = $passToPlayer->fetch_row()[0];
}
$exist = $conn->query("select * from Event where p_id = '{$player_id}' AND g_id = '{$game_id}'");
if ($exist->num_rows == 0) {
// this is a new Event, insert to the Event table.
// rushing touch down should be initialized.
$result = event::insert($player_id, $game_id, $cnt["rushing"], $cnt["passing"], $cnt["fieldgoal"], $cnt["passTo"]);
} else {
// the event is already inserted.
// update the table.
$result = event::update($player_id, $game_id, $cnt["rushing"], $cnt["passing"], $cnt["fieldgoal"], $cnt["passTo"]);
}
$event_id = $result->event_id;
$player_id = $result->player_id;
$game_id = $result->game_id;
printf("insert Event " . "{$event_id}: " . "{$player_id}" . " and " . "{$game_id}" . " succeeded!");
?>
<br>
<?php
}
?>
示例2: addEventToGame
public static function addEventToGame($game_id, $type, $first, $last, $score, $team)
{
$mysqli = new mysqli("classroom.cs.unc.edu", "hongkun", "CH@ngemenow99Please!hongkun", "hongkundb");
/*check the connection*/
if (mysqli_connect_errno()) {
printf("Connection failed: %s\n", mysqli_connect_errno);
exit;
}
// First: add the score to specific team, if team is found
$teamSelected = $mysqli->query("select * from Game where (Team1 = '{$team}' || Team2 = '{$team}') && game_id = '{$game_id}'");
if ($teamSelected->num_rows == 0) {
header("HTTP/1.0 400 Bad Request");
printMessageJSON("Bad Request, Team Not Match");
exit;
}
$teamSelected = $teamSelected->fetch_row();
$allAcore = [$teamSelected[1] => $teamSelected[3], $teamSelected[2] => $teamSelected[4]];
if ($type == "fieldgoal") {
$allAcore[$team] += 3;
} else {
if ($type == "passing") {
$allAcore[$team] += 7;
} else {
if ($type == "rushing") {
$allAcore[$team] += 7;
}
}
}
// if the score is not match, exit();
if ($allAcore[$team] != $score) {
header("HTTP/1.0 400 Bad Request");
printMessageJSON("Bad Request, Score Not Match");
exit;
}
if ($allAcore[$teamSelected[1]] >= $allAcore[$teamSelected[2]]) {
$winner = [$teamSelected[1] => $allAcore[$teamSelected[1]]];
$loser = [$teamSelected[2] => $allAcore[$teamSelected[2]]];
} else {
$winner = [$teamSelected[2] => $allAcore[$teamSelected[2]]];
$loser = [$teamSelected[1] => $allAcore[$teamSelected[1]]];
}
// Update the team score in Game Table.
$gameUpdated = game::update($game_id, key($winner), key($loser), current($winner), current($loser));
// Second: find the player in the team specified.
// if it exists, return p_id, if not, insert it and return the p_id.
$player_id = $mysqli->query("select player_id from Player where first_name = '{$first}' && last_name = '{$last}' && team_name = '{$team}'");
if ($player_id->num_rows == 0) {
$newPlayer = player::insert($first, $last, $team);
$newPlayer = (array) $newPlayer;
$player_id = intval($newPlayer["player_id"]);
} else {
$player_id = $player_id->fetch_row()[0];
}
// Use the p_id and game_id to find the event of the type,
// if it exists, increase the number of the type
// if not, insert the event.
$eventSelected = $mysqli->query("select event_id from Event where p_id = '{$player_id}' && g_id = '{$game_id}'");
$cnt = ["rushing" => 0, "passing" => 0, "fieldgoal" => 0, "passTo" => NULL];
$cnt[$type]++;
if ($eventSelected->num_rows == 0) {
$event_id = event::insert($player_id, $game_id, $cnt["rushing"], $cnt["passing"], $cnt["fieldgoal"], $cnt["passTo"]);
} else {
$event_id = event::update($player_id, $game_id, $cnt["rushing"], $cnt["passing"], $cnt["fieldgoal"], $cnt["passTo"]);
}
// var_dump($event_id);
$ids = [$game_id, $player_id];
return $ids;
}