samedi 27 juillet 2019

Filtering the table to show from database

I have 2 tables in my db: Campaigns and Logs.In Campaigns table, these are 2 columns: campaignName and campaignSource. In the website, I want to have a filter that shows the campaignName. But when user chooses the campaignName, it should give the campaignSources and logs related to THAT campaignName.

Here is the form code:

<div class="collapse" id="network-button">

            <form method="POST" action="index.php">
            <?php 


                include "db.php";
                $result = $db -> query("SELECT * FROM Campaigns");
                $campaigns = $result -> fetch_all(MYSQLI_ASSOC);
                echo '<select class="selectpicker" data-live-search="true" name="campaings">';
                foreach ($campaigns as $campaign){

                    echo '<option value='.$campaign['campaignSource'].'>'.$campaign['campaignName'].'</option>';
                }
                echo '</select>';
                echo '<button id="campaign-filter" type="submit">FILTER</button>';
            ?>
            </form>
      </div>

Here is the data will be printed on website, php code:

$result = $db -> query("SELECT * FROM Log WHERE campaignSource= '' "); 

$log = $result -> fetch_all(MYSQLI_ASSOC);

foreach($log as $mylog) {
echo "<tr role='row'>";
echo "<td>";
echo $mylog["campaignSource"];
echo "</td>";
echo "</tr>";
echo "<td>";
echo $mylog["appID"];
echo "</td>";
echo "<td>";
echo $mylog["appName"];
echo "</td>";
  } 

Its not filtering now. Thank you if you can help me to see through the problem




Aucun commentaire:

Enregistrer un commentaire