简体   繁体   中英

combo box MySQL filter for data table

Trying to get my data table to get filtered by combobox. Not sure why its not posting back the results. it does in phpMyAdmin

The queries are set to the values of the drop down box which are needed to pull data to table below.

Not able to get the data to show in the data table on submit. Sorry im new a this and learning a lot everyday! not sure why its not showing up. Thanks for taking time to him.

PHP Code:

<?php
// connect to database
include('includes/connection.php');

// query & result
$query = "SELECT timestamp, DATE_FORMAT( timestamp + INTERVAL 3 HOUR, '%m-%d-%Y %r') AS formatted_ts, timestamp, marketer, facility, name, type, phone, email, fax, description, locality, state, zip, latlng FROM leads WHERE marketer  =  '".$marketeer."' ORDER BY timestamp DESC ";
$result = mysqli_query( $conn, $query );

// query & result
/*$query = "SELECT DATE_ADD(timestamp, INTERVAL 3 HOUR), timestamp, marketer, facility, name, type, description, locality, state, zip, latlng FROM leads WHERE marketer  <>  'Tommy' AND DATE(`timestamp`) = CURDATE()
ORDER BY DATE_ADD(timestamp, INTERVAL 3 HOUR) DESC";
$result = mysqli_query( $conn, $query );*/

// close the mysql connection
mysqli_close($conn);

include('includes/header.php');
?>

HTML Code:

    <div class="col-sm-8 text-left"> 
      <h1>Todays' Marketing Leads<?php echo $row_User['FirstName']; ?> <?php echo $row_User['LastName']; ?>.</h1>
    <hr>
        <form action="" method="post">
    <select name="marketeers">
        <option value="Scott">Scott</option>
        <option value="Tammy">Tammy</option>
        <option value="Joey">Joey</option>
    </select>
    <input type="submit">
</form>
        <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['DATE_ADD(timestamp, INTERVAL 3 HOUR)'] . "</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>

Not sure what header.php file refers to. Is it the file containing the table?

In that case, please ensure you're loading the PHP page with database connection and sql but not the header.php file in the web browser.

This way, first database $result is initialized and then data fed into the table via the loop.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM