PHP 下拉框根据选择重定向到不同的 URL?
有一个下拉框,其中可以包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有点困惑(尤其是你的第二个代码片段)。如果我正确理解您的问题,您应该在您的元素中使用 onChange 事件。
例子
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
在这一行之后:
您可以添加类似这样的内容:
这将立即跳出流程并重定向它们。如果您需要先向数据库写入某些内容或其他内容,请随意将其放在代码中。
或者,您可以使用 if...else,如下所示:
After this line:
You would add in something like this:
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:
最终恢复到旧的代码,结果证明它可以工作,但我们没有意识到这一点。解决方法如下:
这从输出中排除了“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:
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.