duanquanhan2333 2015-07-19 22:12
浏览 24
已采纳

将提交的表单结果显示为URL链接列表

First of all my PHP skills are kinda limited, Hence my question to you here. I have built a fairly complex form with multiple inputs(text boxs and drop downs) which are stored in a MYsql DB. When the form is submitted it displays on a new page as completed reports. These completed reports display one under the next every time the form is submitted. My question is, How can i get the reports displayed to show as a list of links to the individual reports rather then a list of complete reports. I hope i've explained the situation well enough.

Code snippit from viewpage.php


<html>
<head>

<body>

<?php
                mysql_connect("localhost","user","passwrd");
                mysql_select_db("dtbase");
                $order = "SELECT * FROM jobrequest" ;
                $result = mysql_query($order);
                while ($row=mysql_fetch_array($result)){


?>          
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div style="padding:15px 0px 0px 100px;">
<table cellpadding="0" cellspacing="0" border="0"  style="vertical-align:middle;width: 1139px; background-color:#213568; height:36px;">
    <tr>
        <td class="topbar">Client Request Form</td>
        <td style="width:900px;"></td>
        <td class="topbar"><a style="color:#ffffff;" href="logout.php?logout">Logout</a></td>
    </tr>
</table>
<div class="main-wrap">
<div class="content">
<table cellpadding="0" cellspacing="0" border="0"  style="width: 1137px; background-color:#ffffff; height:5px;">
    <tr>
        <td></td>
    </tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" >
    <tr>
                                <td style="vertical-align:top; width:5px;"></td>
         <td style="vertical-align:top;"><?php include("includes/clientchoices.php"); ?></td>
        <td style="vertical-align:top; padding:0px 5px 15px 5px;">
                <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                                <td style="vertical-align:top; width:1002px;"> <h1> Dashboard</h1></td>
                </tr>
                <tr>
                                <td style="vertical-align:top; background-color:#f5f5f5;"><h2>Job Request Form</h2></td>
                </tr>
                  <tr>
                                <td style="vertical-align:top; background-color:#ffffff; height:5px;"> </td>
                </tr>
                <tr>
                                <td>
                    <div class="form">
                    <table cellspacing="0" cellpadding="0" border="0" style="width:998px">
                         <tr>
                            <td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center>
                            </td>
                         </tr>
                         <tr>  
                            <td>
                                <div style="padding:10px 0px 10px 0px;">
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td class="headingsa">Project Leader:</td><td class="answersa"><div class= "typesectiona"><?php echo ($row['project_leader'] ); ?></div></td>
                                            <td class="headingsb">Contact Number:</td><td class="answersb"><div class= "typesectionb"><?php echo ($row['contact_number'] ); ?></div></td>
                                            <td class="headingsc">Company Details:</td><td class="answersc"><div class= "typesectionc"><?php echo ($row['company_details'] ); ?></div></td>
                                        </tr>
                                    </table>
                               </div>
                          </td>
                         </tr>
                         <tr>  
                            <td>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td class="headings5">Contact Person On Site:</td><td class="answers5"><div class= "typesection5"><?php echo ($row['contactperson_onsite'] ); ?></div></td>
                                        <td class="headings6">Contact Details:</td><td class="answers6"><div class= "typesection6"><?php echo ($row['contact_no'] ); ?></div></td>
                                        <td class="headings7">Date:</td><td class="answers7"><div class= "typesection7"><?php echo ($row['date'] ); ?></div></td>
                                    </tr>
                                </table>
                            </td>  
                         </tr>
                         <tr>  
                            <td>
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td class="headings1">Job/Order Number:</td><td class="answers1"><div class= "typesection1"><?php echo ($row['job_order_number'] ); ?></div></td>
                                        <td class="headings2">Document Number:</td><td class="answers2"><div class= "typesection2"><?php echo ($row['doument_number'] ); ?></div></td>
                                        <td class="headings3">QCP:</td><td class="answers3"><div class= "typesection3"><?php echo ($row['qcp'] ); ?></div></td>
                                        <td class="headings4">Page No:</td><td class="answers4"><div class= "typesection4"><?php echo ($row['pageno'] ); ?></div></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>

                    <table cellspacing="0" cellpadding="0" border="0">
                        <tr>

                            <td width="15px"></td>
                            <td><a class="othersubmitsLink" href="actionpdf.php">Email to Spectra</a></td>
                        </tr>                                         
                    </table>
                    </div>
                    </td>
                </tr>
            </table>
         </td>           
    </tr>
</table>  
</div>
</div>
</div>
<?php
}
?>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • douqian4411 2015-07-20 05:08
    关注

    You will need a separate PHP script for displaying a report based on a supplied ID. This separate script would look something like this:

    Using mysqli

    <?php
        $conn = new mysqli("localhost", "user", "passwrd", "dtbase");
        $jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
        $jrQry->bind_param('i', $_GET['jobrequest_id']);
        $jrQry->execute();
        $jobrequestResult = $jrQry->get_result();
        $jobrequest = $jobrequestResult->fetch_assoc();
    
        // At this point, $jobrequest will contain the jobrequest record you want to display.
    ?>
    <!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
    

    Note that I have used mysqli in this example, if this is unsuitable you can use the old-style mysql commands, but for many many reasons (security chief among them) I would strongly suggest against this.

    Using mysql

    <?php
        mysql_connect("localhost","user","passwrd");
        mysql_select_db("dtbase");
        $order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
        $result = mysql_query($order);
        $jobrequest = mysql_fetch_array($result);
    
        // At this point, $jobrequest will contain the jobrequest record you want to display.
    ?>
    <!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
    

    Save this page as "viewjobrequest.php" and you will be able to load a given job request's report by supplying the jobrequest ID as a parameter in the URL, like so:

    http://address_of_site/viewjobrequest.php?jobrequest_id=X
    

    Now you can automatically generate a list of links to these pages by looking up your complete set of jobrequests and iterating over them, but instead on outputting a full report, just output a link:

    Using mysqli

    <?php
        $conn = new mysqli("localhost", "user", "passwrd", "dtbase");
        $jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
        $jrQry->bind_param('i', $_GET['jobrequest_id']);
        $jrQry->execute();
        $jobrequestResult = $jrQry->get_result();
    ?>
        <ul>
    <?php
        while ($jobrequest = $jobrequestResult->fetch_assoc())
        {
    ?>    
          <li>
            <a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
              View job request #<?php echo $jobrequest['jobrequest_id']; ?>
            </a>
          </li>
    <?php
        }
    ?>
        </ul>
    

    Using mysql

    <?php
        mysql_connect("localhost","user","passwrd");
        mysql_select_db("dtbase");
        $order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
        $result = mysql_query($order);
    ?>
        <ul>
    <?php
        while ($jobrequest = mysql_fetch_assoc($result))
        {
    ?>    
          <li>
            <a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
              View job request #<?php echo $jobrequest['jobrequest_id']; ?>
            </a>
          </li>
    <?php
        }
    ?>
        </ul>
    

    Note: I have deliberately omitted large portions of your HTML, you can add as much extra HTML as you need, I've just offered the bare bones to get you started.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?