PHP下拉框根据选择重定向到不同的URL?

PHP下拉框根据选择重定向到不同的URL?,php,mysql,drop-down-menu,sql,Php,Mysql,Drop Down Menu,Sql,有一个下拉框,其中可以包含1-3种出版物,具体取决于一个人订阅的酒吧: <?php foreach ($userCurrSubs as $pubChoice) { ?> <option value=" <?php { echo $pubChoice->redirect_url ?>"> <?php echo $pubChoice->pub_name ?> </option> 让我们称之为出版物:GunsAmmo、Fiel

有一个下拉框,其中可以包含1-3种出版物,具体取决于一个人订阅的酒吧:

<?php foreach ($userCurrSubs as $pubChoice) { ?>
<option value="
<?php { echo $pubChoice->redirect_url ?>">
<?php echo $pubChoice->pub_name  ?>
</option>
让我们称之为出版物:GunsAmmo、FieldStream和PsychologyToday。(上述代码中的pub_名称)

GunsAmmo和FieldStream工作正常。但是,当有人选择PsychologyToday时,他们需要被发送到一个完全不同的URL,比如,并且不需要将上面的任何登录业务一起发送。

(更好的是,最好不要让PsychologyToday出现在列表中,即使他们订阅了它,,但我怀疑这将是一个更难解决的问题。)

实现这一目标的最佳方式是什么?我不是程序员,所以放轻松点。

我有点困惑(特别是你的第二个代码片段)。如果我正确理解了您的问题,您应该对元素使用onChange事件

范例

<html>
   <select onChange="document.location.href=this[selectedIndex].value">
        <option value="www.example.com"> Option 1 </option>
    </select>
</html>

选择1
在这一行之后:

$temppubItem->pub_name = $row_Recordset2['pub_name'];
您可以添加如下内容:

while($row_Recordset2 = mysql_fetch_assoc($pubResultSet)){
$temppubItem = new PubItem();
$temppubItem->pub_name = $row_Recordset2['pub_name'];
$redirectURLtemp = $redirectURL . $temppubItem->pub_name. "/login/login?Read=";
$redirectURLtemp  = $redirectURLtemp . urlencode($fromBasedURL . $temppubItem->pub_name );
$utcCurrentDate = gmdate ('Y-m-d');
$md5Temp = $loginUsername . $utcCurrentDate . 'none' . $Secret;
#error_log("string for md5=".$md5Temp);
$md5Temp = md5($md5Temp);
$redirectURLtemp = $redirectURLtemp . '&Id=' . $loginUsername . '&d=' . $utcCurrentDate . '&r=none' . '&c=' . $md5Temp;
$temppubItem->redirect_url = $redirectURLtemp;
error_log("list URL to choose.. ".$redirectURLtemp);
$userCurrSubs[] = $temppubItem;
};
if ($temppubItem->pub_name == 'PsychologyToday') {
   // do your redirect here
   header('Location: http://www.psychologytoday.com/');
   exit();
}
if ($temppubItem->pub_name == 'PsychologyToday') {
    $redirectURLtemp = 'http://www.psychologytoday.com/';
} else {
    // do all that complicated stuff here where you set $redirectURLtemp
    // with the fancy login stuff
}
// do your redirecting after closing your if/else:
header('Location: ' . $redirectURLtemp);
这将立即跳出流并重定向它们。如果您需要先向数据库中写入一些内容或其他内容,请稍后将其放在代码中

或者,您可以使用if…else,如下所示:

while($row_Recordset2 = mysql_fetch_assoc($pubResultSet)){
$temppubItem = new PubItem();
$temppubItem->pub_name = $row_Recordset2['pub_name'];
$redirectURLtemp = $redirectURL . $temppubItem->pub_name. "/login/login?Read=";
$redirectURLtemp  = $redirectURLtemp . urlencode($fromBasedURL . $temppubItem->pub_name );
$utcCurrentDate = gmdate ('Y-m-d');
$md5Temp = $loginUsername . $utcCurrentDate . 'none' . $Secret;
#error_log("string for md5=".$md5Temp);
$md5Temp = md5($md5Temp);
$redirectURLtemp = $redirectURLtemp . '&Id=' . $loginUsername . '&d=' . $utcCurrentDate . '&r=none' . '&c=' . $md5Temp;
$temppubItem->redirect_url = $redirectURLtemp;
error_log("list URL to choose.. ".$redirectURLtemp);
$userCurrSubs[] = $temppubItem;
};
if ($temppubItem->pub_name == 'PsychologyToday') {
   // do your redirect here
   header('Location: http://www.psychologytoday.com/');
   exit();
}
if ($temppubItem->pub_name == 'PsychologyToday') {
    $redirectURLtemp = 'http://www.psychologytoday.com/';
} else {
    // do all that complicated stuff here where you set $redirectURLtemp
    // with the fancy login stuff
}
// do your redirecting after closing your if/else:
header('Location: ' . $redirectURLtemp);

最终恢复到原来可以工作的旧代码,而我们没有意识到这一点。以下是修复方法:

$querySQL = "SELECT pub_name FROM pub_subscriber WHERE (pub_name='GunsAmmo' OR pub_name='FieldStream')" ;
这将从输出中排除“Psychologytody”出版物


非常感谢您的帮助,尽管XP84和Victolla将记住您的解决方案,以备将来使用。

感谢您的帮助Victolla,这似乎是我可以做到这一点的一种方法。感谢您的帮助XP84-这几乎奏效了,但我在代码中遇到了另一个错误。