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

发布于 2024-10-22 00:55:45 字数 1550 浏览 3 评论 0原文

有一个下拉框,其中可以包含 1-3 个出版物,具体取决于一个人订阅了哪些 pub:

<?php foreach ($userCurrSubs as $pubChoice) { ?>
<option value="
<?php { echo $pubChoice->redirect_url ?>">
<?php echo $pubChoice->pub_name  ?>
</option>

当用户选择所需的出版物时,他会被重定向到特定的 URL(上面代码中的redirect_url)。 redirect_url 代码如下所示:

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;
};

让我们将出版物命名为:GunsAmmo、FieldStream 和 PsychologyToday。 (上面代码中的 pub_name)

GunsAmmo 和 FieldStream 工作正常。但是,当有人选择 PsychologyToday 时,他们需要被发送到完全不同的 URL,例如 http://www.psychologytoday .com ,并且没有任何上面的登录业务随之发送。

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

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

Have a dropdown box which can have between 1-3 publications in it, depending on which pubs a person has subscribed to:

<?php foreach ($userCurrSubs as $pubChoice) { ?>
<option value="
<?php { echo $pubChoice->redirect_url ?>">
<?php echo $pubChoice->pub_name  ?>
</option>

When the user selects his desired publication, he is redirected to a particular URL (redirect_url in the code above). The redirect_url code looks like this:

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;
};

Let's call the publications: GunsAmmo, FieldStream, and PsychologyToday. (pub_name in the code above)

GunsAmmo and FieldStream are working fine. However, when someone selects PsychologyToday, they need to be sent to a completely different URL, like http://www.psychologytoday.com , and not have any of the login business above sent along with it.

(Even better, it would be preferable to have PsychologyToday NOT show up in the list at all, even if they're subscribed to it, but I suspect that would be a tougher nut to crack.)

What's the best way to accomplish this? Am not a programmer, so go easy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南风起 2024-10-29 00:55:45

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

例子

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

I'm a little confused (especially by your second code snippet). If I'm understanding your question correctly, you should use an onChange event with your element.

Example

<html>
   <select onChange="document.location.href=this[selectedIndex].value">
        <option value="www.example.com"> Option 1 </option>
    </select>
</html>
浮光之海 2024-10-29 00:55:45

在这一行之后:

$temppubItem->pub_name = $row_Recordset2['pub_name'];

您可以添加类似这样的内容:

if ($temppubItem->pub_name == 'PsychologyToday') {
   // do your redirect here
   header('Location: http://www.psychologytoday.com/');
   exit();
}

这将立即跳出流程并重定向它们。如果您需要先向数据库写入某些内容或其他内容,请随意将其放在代码中。

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

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);

After this line:

$temppubItem->pub_name = $row_Recordset2['pub_name'];

You would add in something like this:

if ($temppubItem->pub_name == 'PsychologyToday') {
   // do your redirect here
   header('Location: http://www.psychologytoday.com/');
   exit();
}

That would immediately jump out of the flow and redirect them. feel free to place that later in the code instead, if you need to write something to your DB first or something.

Alternatively, you could use an if...else like this:

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);
明天过后 2024-10-29 00:55:45

最终恢复到旧的代码,结果证明它可以工作,但我们没有意识到这一点。解决方法如下:

$querySQL = "SELECT pub_name FROM pub_subscriber WHERE (pub_name='GunsAmmo' OR pub_name='FieldStream')" ;

这从输出中排除了“PsychologyToday”出版物。

非常感谢 XP84 和 vicTROLLA 提供的帮助,我们将记住您的解决方案以供将来使用。

Ended up reverting to older code which turned out to be working and we hadn't realized it. Here was the fix:

$querySQL = "SELECT pub_name FROM pub_subscriber WHERE (pub_name='GunsAmmo' OR pub_name='FieldStream')" ;

This excludes the "PsychologyToday" publication from the output.

Thanks so much for the help though XP84 and vicTROLLA, will keep your solutions in mind for future use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文