PHP GET的复杂问题

时间:2015-01-16 02:56:43

标签: php get html-form

我有form输入匹配号并通过PHP GET提交到网址,说test.php?match=

我添加了易于使用的箭头(时间对于最终用户来说很重要),在一场比赛和一场比赛中上升,只要您不先输入数字,它们就能正常工作。箭头添加数字OK,我可以从0开始向上,但是如果我从另一个数字开始它会工作一次但是从URL中删除数字(例如,导航到test.php?match=3并按向右箭头显示匹配4但URL已更改为test.php?match=

这是我的代码:

<?php
$next = $_GET["match"] + "1";
$last = $_GET["match"] - "1";
echo "<form action=\"test.php\" method=\"GET\">
    Match<br>
    <input style=\"font-size:24px;\" autofocus=\"autofocus\" type=\"number\" size=\"4\" name=\"match\" value=\"" . $_GET["match"] . "\">
    <a href=\"sql.php?match=\"><button style=\"font-size:24px;\">Show All</button></a>
    <a href=\"sql.php?match=" . $last . "\"><button style=\"font-size:24px;\"><</button></a>
    <a href=\"sql.php?match=" . $next . "\"><button style=\"font-size:24px;\">></button></a>
    <input style=\"font-size:24px;\" type=\"submit\" value=\"Submit\">
    </form>";
?>

谢谢!

2 个答案:

答案 0 :(得分:0)

尝试用以下内容替换您的表单:

echo "<form action= 'test.php' method='GET'>
        Match<br>
        <input style='font-size:24px;' autofocus='autofocus' type='number' size='4' name='match' value='" . $_GET["match"] . "'>
        <a href='sql.php?match='><button style='font-size:24px;'>Show All</button></a>
        <a href='sql.php?match=" . $last . "' style = 'padding: 5px; border-radius: 5px; background: rgb(240, 240, 240); border: 1px solid silver;'><<<</a>
        <a href='sql.php?match=" . $next . "' style = 'padding: 5px; border-radius: 5px; background: rgb(240, 240, 240); border: 1px solid silver;'>>>></a>
        <input style='font-size:24px;' type='submit' value='Submit'>
        </form>";

<a>如果点击其中的<button>,则不会将您引导至该链接。您似乎点击了<button>而不是<a>。因此,作为建议,您可以为<a>设置样式,使其显示为按钮。

答案 1 :(得分:0)

也许这样的事情就是你想要的:

<?php
    $next = $_GET["match"] + "1";
    $last = $_GET["match"] - "1";
?>

<form action="" method="GET">
    Match<br>
    <input style="font-size:24px;" autofocus="autofocus" type="number" size="4" name="match" value="<?php echo $_GET['match'] ?>">
    <button style="font-size:24px;"><a href="?" style="text-decoration:none; color:#000;">Show All</a></button>
    <button style="font-size:24px;"><a href="?match=<?php echo $last ?>" style="text-decoration:none; color:#000;">&lt;</a></button>
    <button style="font-size:24px;"><a href="?match=<?php echo $next ?>" style="text-decoration:none; color:#000;">&gt;</a></button>
    <input style="font-size:24px;" type="submit" value="Submit">
</form>

我认为最好将php和html表单分开(不要回显表单,而只是要传递的值)