过滤MYsql数据以获取静态页面报告

时间:2016-05-10 06:42:50

标签: php mysql

我已创建了一个报告页面,如果您愿意,可以从数据库中提供有关每个营销人员的结果。我目前正在尝试使报告页面动态化。我想为每个营销人员提供一个下拉框。

因此,寻找方法为每个营销人员提供一个组合框,我可以点击它来显示他们的报告。我知道值将= MySQL表达式只是不确定如何实现这一点。目前,它们都有自己的页面和指向这些页面的链接。当需要添加内容时,编辑所有当前页面变得麻烦。

当前数据库表如下。

Column  Type    Null    Default Comments
id  int(10) No       
timestamp   timestamp   No  CURRENT_TIMESTAMP    
marketer    varchar(25) Yes     NULL     
name    varchar(100)    Yes     NULL     
type    varchar(25) Yes     NULL     
phone   varchar(12) Yes     NULL     
email   varchar(50) Yes     NULL     
fax varchar(12) Yes     NULL     
description varchar(500)    Yes     NULL     
locality    varchar(35) Yes     NULL     
state   varchar(25) Yes     NULL     
zip varchar(5)  Yes     NULL     
latlng  varchar(256)    Yes     NULL     
facility    varchar(100)    Yes     NULL     
marketer_id

我对个人营销人员的查询。

$query = "SELECT * FROM leads WHERE marketer = 'Scott' ORDER BY `timestamp` DESC";
$result = mysqli_query( $conn, $query );

结果取得了

   `<div class="col-sm-8 text-left"> 
      <h1>Todays' Marketing Leads<?php echo $row_User['FirstName']; ?> <?php echo $row_User['LastName']; ?>.</h1>
    <hr>
    <table border="1">

<?php echo $alertMessage; ?>

<table class="table table-striped table-bordered">
    <tr>
        <th>Timestamp</th>
        <th>Marketer</th>
        <th>Facility</th>
        <th>Name</th>
        <th>Type</th>
        <th>Description</th>
        <th>City</th>
        <th>State</th>
        <th>Zip</th>
        <th>Location Mapped</th>
    </tr>

    <?php

    if( mysqli_num_rows($result) > 0 ) {

        // we have data!
        // output the data

        while( $row = mysqli_fetch_assoc($result) ) {
            echo "<tr>";

            echo "<td>" . $row['timestamp'] . "</td><td>" . $row['marketer'] . "</td><td>" . $row['facility'] . "</td><td>" . $row['name'] . "</td><td>" . $row['type'] . "</td><td>" . $row['description'] . "</td><td>" . $row['locality'] . "</td><td>" . $row['state'] . "</td><td>" . $row['zip'] . "</td><td>" . $row['latlng'] . "</td>";



            echo "</tr>";
        }
    } else { // if no entries
        echo "<div class='alert alert-warning'>There are no current leads today!</div>";
    }

    mysqli_close($conn);

    ?>


</table>`

Report HTML code

Html Report dynamic

1 个答案:

答案 0 :(得分:1)

您可以使用选择菜单在页面中添加一个小表单,您可以在其中选择您的市场营销人员。像这样:

<form action="" method="post">
    <select name="marketeers">
        <option value="Scott">Scott</option>
        <option value="marketeer2">marketeer 2</option>
        <option value="marketeer3">marketeer 3</option>
        ...
    </select>
    <input type="submit">
</form>

提交此表单时,它会将信息发送给自己并重新加载页面。

然后阅读php脚本中的发送信息并将其添加到您的查询中:

$marketeer = $_POST['marketeers'];
$query = "SELECT * FROM leads WHERE marketer = '".$marketeer."' ORDER BY `timestamp` DESC";

希望它有所帮助。