jeudi 15 février 2018

Using checkboxes to select tables

I am working on a school project, but I got stuck on this part where I am trying to implement checkboxes as a user input. I have a database with 17 tables each with a number of columns, ranging from 3 up to 21 columns. Some one else in my group created a website as a user interface. On this website we have 17 checkboxes, each with a table name. The goal is for the user to be able to select a few checkboxes, click submit and that then these tables will appear (inner)joined together.

I have the code, but at the moment I tried it with a whole bunch of IF statemets which I knew wouldn't work, and it doesn't :)

Can anybody help me?

User interface

At the moment my code is about 500 lines as there are some other tables that I am working with as well. I don't really know what part of the code is neccessary for this part, but here is the PHP before the HTML code:

<?php
$con=mysqli_connect("localhost","root","","test_terma");

$sql = "SELECT * FROM pcf
    INNER JOIN cur ON pcf.pcf_name = cur.cur_pname
    ";

  $result = mysqli_query($con, $sql);

if(isset($_POST['search']))
 {
    $searchq = $_POST['search'];
    $sql = "SELECT * FROM pcf
            INNER JOIN cur ON pcf.pcf_name = cur.cur_pname
            WHERE pcf_name LIKE '%$searchq'";

  $result = mysqli_query($con, $sql);
 }
if(isset($_POST['table']))
 {
    $sql = "SELECT * FROM pcf";
    $result = mysqli_query($con, $sql);
 }
?>

Maybe it is also useful to have the checkbox code in HTML:

<html>

<head>
   <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
<title>Website</title>
<link rel="stylesheet" href="Stylesheet.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="JavaScript.js"></script>
</head>

<body>
<img class="resize" src="Terma.jpg" alt="">
<hr width="100%" color="#252525" size="1px">

<div class="row">
    <div class="search" style="background-color: #fff;">
        <h1>Search</h1>
        <div class="searchbar">
            <form class="example" action="terma_f.php" method="post">
                <input type="text" size="20" placeholder="Search" name="search">
                <button type="submit" class="btn btn-default">
                <i class="fa fa-search"></i>
                </button><h1>Tables</h1>
                <h4>
                <input type="checkbox" name="PCF" value="PCF">PCF<br>
                <input type="checkbox" name="CUR" value="CUR">CUR<br>
                <input type="checkbox" name="LGF" value="LGF">LGF<br>
                <input type="checkbox" name="MCF" value="MCF">MCF<br>
                <input type="checkbox" name="CAF" value="CAF">CAF<br>
                <input type="checkbox" name="CAP" value="CAP">CAP<br>
                <input type="checkbox" name="PLF" value="PLF">PLF<br>
                <input type="checkbox" name="VPD" value="VPD">VPD<br>
                <input type="checkbox" name="PID" value="PID">PID<br>
                <input type="checkbox" name="TPCF" value="TPCF">TPCF<br>
                <input type="checkbox" name="GRPK" value="GRPK">GRPK<br>
                <input type="checkbox" name="GRP" value="GRP">GRP<br>
                <input type="checkbox" name="GRPA" value="GRPA">GRPA<br>
                <input type="checkbox" name="TXF" value="TXF">TXF<br>
                <input type="checkbox" name="TXP" value="TXP">TXP<br>
                <input type="checkbox" name="OCF" value="OCF">OCF<br>
                <input type="checkbox" name="OCP" value="OCP">OCP<br></h4>
            </form>
        </div>
    </div>

    <div class="divider" style="background-color: #000;">
        <h3> </h3>
    </div>

    <?php
        if(mysqli_num_rows($result) > 0)
        {
?>




Aucun commentaire:

Enregistrer un commentaire