Background : The server is set up by the IT department at my work place. I intend to host the website from said machine but I've been doing developmental work from my own laptop.
Problem : the following part of the code shows as a text in my site and none of the items in the table are shown.
$dbh = new PDO( "sqlsrv:server=".$host."; Database=".$dbName, $dbUser, $dbPass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM testmto";
I'm a total beginner in coding and the following php/html code is obtained from one of the threads on here.
<?php
$host="xx";
$dbName="xx";
$dbUser="xx";
$dbPass="xx";
$dbh = new PDO( "sqlsrv:server=".$host."; Database=".$dbName, $dbUser, $dbPass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "SELECT * FROM testmto";
?>
<table>
<thead>
<tr>
<td>Key</td>
<td>Project Name</td>
<td>Section</td>
<td>Item ID</td>
<td>Item Type</td>
<td>Unit Weight</td>
<td>Base NLA</td>
<td>Eng CF</td>
<td>Fab CF</td>
<td>Specs</td>
</tr>
</thead>
<tbody>
<?php
foreach ($dbh->query($sql) as $rows){
?>
<tr>
<td><?php echo intval($rows['p_key'])?></td>
<td><?php echo $rows['proj_name']?></td>
<td><?php echo $rows['section']?></td>
<td><?php echo $rows['item_id']?></td>
<td><?php echo $rows['item_type']?></td>
<td><?php echo $rows['unit_weight']?></td>
<td><?php echo $rows['base_nla']?></td>
<td><?php echo $rows['eng_cf']?></td>
<td><?php echo $rows['fab_cf']?></td>
<td><?php echo $rows['specs']?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
The goal is to display whole SQL tables into the site for other people to see.
Other objectives which I will post another thread about is to allow them to:
- Filter the table
- Consolidate the table
- Download filtered and consolidated table as .csv/.xlsx file