donglu5047 2011-11-19 03:52
浏览 39
已采纳

如何在页面加载时使用一些PHP代码取代其他PHP代码

I currently have this code in the page/div when you load it without anything in the url bar (a.k.a just index.php)

<?php echo"<h1>For all of your Citation needs!</h1>

<div >

<p>

This page is for any citations you would need to make for reports or essays. Once you enter in the needed information for your sourse, it will spit out the citations in <a href='http://owl.english.purdue.edu/owl/resource/747/01/'>MLA</a> &amp; <a href='http://owl.english.purdue.edu/owl/resource/560/01/'>APA</a> format.</p>
<p >In development is a system where your citations are stored in a database and everytime you make a new one, you will be given related reference material to help your research. Also available soon will be the ability to look up references using related fields such as:</p>

<ul>
<li>Authors</li>
<li>Ttile of Work</li>
<li>Publishing Company</li>
<li>Journal Publisher</li>
<li>Academic Source</li>
<li>Something else will go here</li>
</ul>


</div>";  ?>

When I click a link on the site to load different form data (index.php?form=book), I want that form data to take place of the stuff already in that div...for example:

<?php
switch ($_GET['form'])
{
    case 'book':
        ?>
        <form method="POST" action="thispage.php">
            <input name="" type="text" value="fghfghfghfghfghfh" />
        </form>
        <?
        break;
    case 'b': // show form b
        ?>
        <form method="POST" action="thispage.php">
            <!-- form b elements here :) -->
        </form>
        <?
        break;
    case 'c': // show form c
        ?>
        <form method="POST" action="thispage.php">
            <!-- form c elements here :) -->
        </form>
        <?
        break;
}
?>

Is there a way to have ^THIS^ block of PHP code take the place of the other block of php code when in the page/div when you click the link to load the form data?

  • 写回答

1条回答 默认 最新

  • dpbfb7119 2011-11-19 03:59
    关注

    Add the first block of "code" as the default for your switch statement. There are much better ways of building your page, though...

    PHP manual for switch: http://php.net/manual/en/control-structures.switch.php

    EDIT: Sample of your code, updated:

    <?php
        switch ($_GET['form'])
        {
            case 'book':
                ?>
                <form method="POST" action="thispage.php">
                    <input name="" type="text" value="fghfghfghfghfghfh" />
                </form>
                <?
                break;
            case 'b': // show form b
                ?>
                <form method="POST" action="thispage.php">
                    <!-- form b elements here :) -->
                </form>
                <?
                break;
            case 'c': // show form c
                ?>
                <form method="POST" action="thispage.php">
                    <!-- form c elements here :) -->
                </form>
                <?
                break;
            default:
                echo "<h1>For all of your Citation needs!</h1>
    
                    <div >
    
                    <p>
    
                    This page is for any citations you would need to make for reports or essays. Once you enter in the needed information for your sourse, it will spit out the citations in <a href='http://owl.english.purdue.edu/owl/resource/747/01/'>MLA</a> &amp; <a href='http://owl.english.purdue.edu/owl/resource/560/01/'>APA</a> format.</p>
                    <p >In development is a system where your citations are stored in a database and everytime you make a new one, you will be given related reference material to help your research. Also available soon will be the ability to look up references using related fields such as:</p>
    
                    <ul>
                    <li>Authors</li>
                    <li>Ttile of Work</li>
                    <li>Publishing Company</li>
                    <li>Journal Publisher</li>
                    <li>Academic Source</li>
                    <li>Something else will go here</li>
                    </ul>
    
    
                    </div>";
                    break;
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作