从下拉选择中将ID值从一个表传递到另一个表

时间:2017-10-19 17:29:59

标签: php

我错过了什么?

我有一个值下拉列表。我认为一切都运行正常,除非我将结果发布到另一个表格,我似乎无法从第一个表格中获取游戏ID,它只是空白。我错过了与团队和gameID的关联吗?

查询以获取下拉数据:

    $sql = "select s.*, (DATE_ADD(NOW(), INTERVAL " . SERVER_TIMEZONE_OFFSET . " HOUR) > gameTimeEastern or DATE_ADD(NOW(), INTERVAL " . SERVER_TIMEZONE_OFFSET . " HOUR) > '" . $cutoffDateTime . "')  as expired ";
$sql .= "from " . DB_PREFIX . "schedule s ";
$sql .= "inner join " . DB_PREFIX . "teams ht on s.homeID = ht.teamID ";
$sql .= "inner join " . DB_PREFIX . "teams vt on s.visitorID = vt.teamID ";
$sql .= "where s.weekNum = " . $week . " ";
$sql .= "order by s.gameTimeEastern, s.gameID";
//echo $sql;
$query = $mysqli->query($sql) or die($mysqli->error);
if ($query->num_rows > 0) {
    $i = 0;
    while ($row = $query->fetch_assoc()) {
        $sGameID = (int)$row['gameID'];
        $homeTeam = new team($row['homeID']);
        $visitorTeam = new team($row['visitorID']);
        $surv_pick_options_h[$i]=$row['homeID']; 
        $surv_pick_options_v[$i]=$row['visitorID'];
        if ($row['expired']){
        $surv_pick_expired_h[$i]=$row['homeID'];
        $surv_pick_expired_v[$i]=$row['visitorID'];
        }
        $surv_gameID[$i] = (int)$row['gameID'];
        $i++;
        $rowclass = (($i % 2 == 0) ? ' class="altrow"' : '');
        }

        };

下拉选择选项:

$sWeek = (int)getCurrentWeek()+1;
    if ($week < $sWeek){
$survpicks_to_disable = array_slice($survpicks,0,$week-1);

$disabled = array_merge($survpicks_to_disable,$surv_pick_expired_h,$surv_pick_expired_v);

echo '<select name="survpick" id="survpick">
      <option default>Select</option>';

foreach($surv_pick_options_h as $home){
   echo '<option value="'.$home.'"'.(in_array($home,$disabled)?' style="background-color:pink" disabled':'').($home == $currentID?' selected':'').'>'.$home.'</option>';
        }
foreach($surv_pick_options_v as $visitor){
   echo '<option value="'.$visitor.'"'.(in_array($visitor,$disabled)?' style="background-color:pink" disabled':'').($visitor == $currentID?' selected':'').'>'.$visitor.'</option>';
        }
    }
echo '</select>';   
}

最后用结果更新表格:

$sql = "insert into " . DB_PREFIX . "picksurvivor (weekNum, userID, user, gameID, picksurv, showPicks) values (" . $_POST['week'] . ", " . $user->userID . ",'" . $user->userName . "', '" . $surv_gameID . "', '" . $_POST['survpick'] . "',  ". (int)$_POST['showPicks'] . ");";
$mysqli->query($sql) or die('Error deleting survivor pick: ' . $mysqli->error);

1 个答案:

答案 0 :(得分:0)

我发现了一种不同的方法,在插入之后进行更新,基本上强制使用那里的gameID。