-1

I want to display table vertically. Now, It's displaying horizontally. Each and every field is displaying. How can I display table vertically? And one more thing I want to add one more function to the button. Current date added into database when button submit is clicked. For now this code is making my status 0 and not updating date in database.

<html>
    <head>
        <meta name="description" content="website description" />
        <meta name="keywords" content="website keywords, website keywords" />
        <meta http-equiv="content-type" content="text/html; charset=windows-
            1252" />
        <link rel="stylesheet" type="text/css" href="style/style.css" />
        <style>
            <table>
            {
            border-style:solid;
            border-width:2px;
            border-color:pink;
            }
        </style>
    </head>
    <?php
        include 'inc/head.php';

        include 'connection.php';

        $id = $_GET['id'];

        $sql = "SELECT * FROM user WHERE id='$id'";

        $query = mysqli_query($conn, $sql);

        echo "<table border='6'>
          <tr>
              <th>Application Type</th> <br>
              <th>First name</th><br>
              <th>Sur name</th><br>
              <th>title</th>
              <th>Date of Birth</th>
              <th>Gender</th>
              <th>Nationality</th>
              <th>Country of Birth</th>
              <th>Applicant's Location</th>
              <th>alias</th>
              <th>Criminal </th>
              <th>Country of passport</th>
              <th>Passport number</th>
              <th>Passport issue date </th>
              <th>Passport expiry date</th>
              <th>Address </th>
              <th>City</th>
              <th>State</th>
              <th>Postal Code</th>
              <th>Country</th>
              <th>Email Address</th>
              <th>Home Number</th>
              <th>Business Number</th>
              <th>mobile</th>
          </tr>";

        while($row = mysqli_fetch_assoc($query)) {
            echo "<tr>";
            echo "  <td>" . $row['applicationtype'] . "</td>";
            echo "  <td>" . $row['firstname'] . "</td>";
            echo "  <td>" . $row['lastname'] . "</td>";
            echo "  <td>" . $row['title1'] . "</td>";
            echo "  <td>" . $row['dob'] . "</td>";
            echo "  <td>" . $row['gender'] . "</td>";
            echo "  <td>" . $row['nationality'] . "</td>";
            echo "  <td>" . $row['countryofbirth'] . "</td>";
            echo "  <td>" . $row['applicantlocation'] . "</td>";
            echo "  <td>" . $row['alias'] . "</td>";
            echo "  <td>" . $row['criminal'] . "</td>";
            echo "  <td>" . $row['countryofpassport'] . "</td>";
            echo "  <td>" . $row['passportnumber'] . "</td>";
            echo "  <td>" . $row['pid'] . "</td>";
            echo "  <td>" . $row['ped'] . "</td>";
            echo "  <td>" . $row['address'] . "</td>";
            echo "  <td>" . $row['city'] . "</td>";
            echo "  <td>" . $row['state'] . "</td>";
            echo "  <td>" . $row['postalcode'] . "</td>";
            echo "  <td>" . $row['country'] . "</td>";
            echo "  <td>" . $row['email'] . "</td>";
            echo "  <td>" . $row['homephone'] . "</td>";
            echo "  <td>" . $row['businessphone'] . "</td>";
            echo "  <td>" . $row['mobile'] . "</td>";




            echo "</tr>";
        }
        echo "</table><br><br>";

        if(isset($_POST['submit'])) {
            echo $radio = $_POST['radio'];
            $date_clicked = date('Y-m-d H:i:s');

            $sql = "UPDATE user SET visastatus='$radio' AND currentdate='$date_clicked' WHERE id='$id'";
            $query = mysqli_query($conn, $sql);
            if($query) {
                echo "<h4 style='color:green'>Action Performed Successfully....</h4>";
            } else {
                echo "<h4 style='color:red'>Failed.</h4>";
            }
        }
    ?>
        <form method="POST" action="" enctype="multipart/form-data">
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" style="margin-top: 
                8px;">
                <label class="checkbox-inline tourist-rad">
                <input type="radio" name="radio" id="success" 
                    value="Successfull">Successfull
                </label>            
                &nbsp;&nbsp;&nbsp;
                <label class="checkbox-inline tourist-rad">
                <input type="radio" name="radio" id="decline" value="Declined">Declined
                </label>
                &nbsp;&nbsp;&nbsp;
            </div>
            <div class="form-group">
                <button type="submit"  name="submit"  value="submit" class="btn btn-
                    primary" style="float: right;">Update Menu Item</button>
            </div>
    </body>
</html>
GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71
Rimsha Miraj
  • 25
  • 1
  • 8
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code**. – GrumpyCrouton Sep 01 '17 at 14:07
  • [Little Bobby](http://bobby-tables.com/) says **[you are at risk for SQL Injection Attacks](https://stackoverflow.com/q/60174/)**. Learn about [Prepared Statements](https://en.wikipedia.org/wiki/Prepared_statement) for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even **[escaping the string](https://stackoverflow.com/q/5741187)** is not safe! I recommend `PDO`, which I [wrote a function for](http://paragoncds.com/grumpy/pdoquery/#function) to make it extremely **easy**, very **clean**, and way more **secure** than using non-parameterized queries. – GrumpyCrouton Sep 01 '17 at 14:09
  • To display vertical you can use transform: rotate(90deg); if this is what you looking for. – Germano Plebani Sep 01 '17 at 14:09
  • I don't want to rotate my table. I want each cell to be displayed vertically. @GermanoPlebani Like Name:- Rimsha and in the next like my surname. – Rimsha Miraj Sep 01 '17 at 14:11
  • Please stick to one question per post. – M. Eriksson Sep 01 '17 at 14:11
  • Then solve one question for me. @MagnusEriksson – Rimsha Miraj Sep 01 '17 at 14:13
  • Check my answer, is that what you're looking for? – Keno Sep 01 '17 at 14:13
  • You already have an answer. Me solving the question or not doesn't change the fact that you should edit your post to contain only one of the two questions. – M. Eriksson Sep 01 '17 at 14:15
  • Your missing your form ending tag, and your body start tag. – GrumpyCrouton Sep 01 '17 at 14:15
  • *Not Updating To Database Table?* Then, Change `$sql = "UPDATE user SET visastatus='$radio' AND currentdate='$date_clicked' WHERE id='$id'";` to `$sql = "UPDATE user SET visastatus='$radio', currentdate='$date_clicked' WHERE id='$id'";` You Have Problem In Your Update Query. – Nana Partykar Sep 01 '17 at 14:16
  • If you don't want rotate remove tag CSS. Int this case CSS is useless – Germano Plebani Sep 01 '17 at 14:17
  • @NanaPartykar Not working – Rimsha Miraj Sep 01 '17 at 14:19
  • See. I corrected your Update Query. Even though if it's not working. Then, there is other problem related to it. Debug it why it's not working. – Nana Partykar Sep 01 '17 at 14:20

2 Answers2

1

How can I display the table vertically?

Put each heading in a new <tr>. Remember, <tr> stands for table row, while <td> is for each of the elements in that row. This will require some modification of your php code so that you can essentially print a new row, and each td within it.

Edit: To display it vertically as you like, you'd need to modify your existing while loop.

//Print the row
echo "<tr>";

//Print the row heading
<th>Application Type</th>
while($row = mysqli_fetch_assoc($query)) {
        //Print each matching data type inside
        echo "  <td>" . $row['applicationtype'] . "</td>";

}
//Close the row
echo "</tr>";

You'll need to do this functionality for each of the headings you have. You could also use arrays along with nested loops to print all the data cleanly and easily without excess code.

Keno
  • 2,018
  • 1
  • 16
  • 26
  • Table name is displaying vertically thankyou for that but how can I display database table content vertically? @Keno Clayton – Rimsha Miraj Sep 01 '17 at 14:16
  • @RimshaMiraj Simple, just put the database content in each of those ``s. I'll update my answer to give you an idea of how I'd do it. You'll need to use a loop to do it though. – Keno Sep 01 '17 at 14:18
  • @RimshaMiraj this should give you a rough idea as to how it would work. – Keno Sep 01 '17 at 14:31
1

If by "vertically" you mean you want to have 2 columns and 24 rows instead of 24 columns and 2 rows, this will do it for you:

echo "<table border='6'>";
    while($row = mysqli_fetch_assoc($query)) {
        echo "<tr><th>Application Type</th><td>{$row['applicationtype']}</td></tr>";
        echo "<tr><th>First Name</th><td>{$row['firstname']}</td></tr>";
        echo "<tr><th>Surname</th><td>{$row['lastname']}</td></tr>";
        echo "<tr><th>Title</th><td>{$row['title1']}</td></tr>";
        echo "<tr><th>Date of Birth</th><td>{$row['dob']}</td></tr>";
        echo "<tr><th>Gender</th><td>{$row['gender']}</td></tr>";
        echo "<tr><th>Nationality</th><td>{$row['nationality']}</td></tr>";
        echo "<tr><th>Country of Birth</th><td>{$row['countryofbirth']}</td></tr>";
        echo "<tr><th>Applicant's Location</th><td>{$row['applicantlocation']}</td></tr>";
        echo "<tr><th>Alias</th><td>{$row['alias']}</td></tr>";
        echo "<tr><th>Criminal</th><td>{$row['criminal']}</td></tr>";
        echo "<tr><th>Country of Passport</th><td>{$row['countryofpassport']}</td></tr>";
        echo "<tr><th>Passport Number</th><td>{$row['passportnumber']}</td></tr>";
        echo "<tr><th>Passport Issue Date</th><td>{$row['pid']}</td></tr>";
        echo "<tr><th>Passport Expiry Date</th><td>{$row['ped']}</td></tr>";
        echo "<tr><th>Address</th><td>{$row['address']}</td></tr>";
        echo "<tr><th>City</th><td>{$row['city']}</td></tr>";
        echo "<tr><th>State</th><td>{$row['state']}</td></tr>";
        echo "<tr><th>Postal Code</th><td>{$row['postalcode']}</td></tr>";
        echo "<tr><th>Country</th><td>{$row['country']}</td></tr>";
        echo "<tr><th>Email Address</th><td>{$row['email']}</td></tr>";
        echo "<tr><th>Home Number</th><td>{$row['homephone']}</td></tr>";
        echo "<tr><th>Business Number</th><td>{$row['businessphone']}</td></tr>";
        echo "<tr><th>Mobile</th><td>{$row['mobile']}</td></tr>";
    }
echo "</table>";

Additionally, if you are going to be handling such sensitive personal data, you MUST improve your query security starting with mysqli prepared statements using placeholders.

mickmackusa
  • 43,625
  • 12
  • 83
  • 136