Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate HTML Table with MySQL Table Data

Tags:

php

mysql

I'm really new to HTML/PHP and I want to build a simple website that returns the data from my MySQL database in form of a table..

My code looks like this for now:

<?php
  $server = mysql_connect("server", "username", "password"); 
  $db = mysql_select_db("ni354077_2sql1", $server); 
  $query = mysql_query("SELECT * FROM Jobs"); 
?>

         <table>
            <tr>
                <td>AuftragsID</td>
                <td>Startort</td>
                <td>Zielort</td>
                <td>Gewicht</td>
                <td>Fracht</td>
            </tr>

            <?php
               while ($row = mysql_fetch_array($query)) {
                   echo "<tr>";
                   echo "<td>".$row[AuftragsID]."</td>";
                   echo "<td>".$row[Startort]."</td>";
                   echo "<td>".$row[Zielort]."</td>";
                   echo "<td>".$row[Gewicht]."</td>";
                   echo "<td>".$row[Fracht]."</td>";
                   echo "</tr>";
               }

            ?>
        </table>

However it doesn't seem to be working properly. My table is full of "echo (..)" here is a Picutre of what it looks like: http://i.imgur.com/xw9bWy5.png

Am I missing something ? I'm coming from C# WinForms and am confused with that.

like image 382
Tobias Karl Avatar asked Sep 28 '22 17:09

Tobias Karl


1 Answers

use this u have missed single quotes around php values, put like below

          <?php
               while ($row = mysql_fetch_array($query)) {?>
                   <tr>
                   <td><?php echo $row['AuftragsID'];?></td>
                   <td><?php echo $row['Startort'];?></td>
                   <td><?php echo $row['Zielort'];?></td>
                   <td><?php echo $row['Gewicht'];?></td>
                   <td><?php echo $row['Fracht'];?></td>
                   </tr>
              <?php  } ?>
like image 77
Vivek Singh Avatar answered Oct 03 '22 00:10

Vivek Singh