I want to search and execute the data with the same orderid . Unfortunately it says
Fatal error: Cannot use object of type mysqli_result as array in
C:\wamp64\www\Workshop1\admin\ordersearch.php on line 114
if(isset($_POST['search']))
{
// id to search
$Orderid = $_POST['Orderid'];
// connect to mysql
$connect = mysqli_connect("localhost", "root", "","workshop1");
// mysql search query
$query = "SELECT * FROM orders WHERE Orderid = $Orderid ;";
$result = mysqli_query($connect, $query);
// if id exist
// show data in inputs
if(mysqli_num_rows($result) > 0)
{
while ($row = mysqli_fetch_array($result))
{?>
<td style='border-bottom: 1px solid #b3b3b3;' align='center'><?php echo $result["Orderid"];?></td>
<td style='border-bottom: 1px solid #b3b3b3;' align='center'><?php echo $result["productid"];?></td>
<td style='border-bottom: 1px solid #b3b3b3;' align='center'><?php echo $result["price"];?></td>
<td style='border-bottom: 1px solid #b3b3b3;' align='center'><?php echo $result["quantity"];?></td>
<td style='border-bottom: 1px solid #b3b3b3;' align='center'><?php echo $result["custid"];?></td>
<?php
}
}
// if the id not exist
// show a message and clear inputs
else {
echo "Undifined ID";
}
mysqli_free_result($result);
mysqli_close($connect);
}
you must write your code like this because if you don't it will recognize $Orderid as
a string.
$query = "SELECT * FROM orders WHERE Orderid = '" . $Orderid. "' limit 1 ";
and change this
<td style='border-bottom: 1px solid #b3b3b3;' align='center'>
<?php echo $row["Orderid"];?>
</td>
You are store data in loop using $row variable so that you need to use $row['orderId']; if you print data in loop for ex. print_r($row);
Related
I have a problem in inserting table from my database to div.
html code:
<div class="content">
<?php
$query = "SELECT name, surname FROM players";
$response = #mysqli_query($dbc, $query);
if($response) {
echo' <table align="left"
cellspacing="5" cellpadding="8" >
<tr><td align="left"><b>First Name</b></td>
<td align="left"><b>Last Name</b></td></tr>';
while($row = mysqli_fetch_array($response)) {
echo '<tr><td align="left">' .
$row['imie'] . '</td><td align="left">' .
$row['nazwisko'] . '</td><td align="left">';
echo '</tr>';
}
echo '</table>';
} else {
echo "Couldn't issue database query";
echo mysqli_error($dbc);
}
mysqli_close($dbc);
?>
</div>
css code:
.content {
width: 1000px;
margin-left: auto;
margin-right: auto;
background-color: #ffffff;
color: #000000;
border-bottom: 14px solid #333333;}
Is there a way to insert this table to this div? Because when I'm loading this, the table is under my div'content'. The table should be in blank field 'a'.
Screenshot
Correctly indenting your code would have allowed you o spot the error relatively easily - there is an open td element. Either remove the last td from the echo statement in the loop or add additional td pair to first row in table so that they balance ( unless you use colspan attributes )
<style>
.content table tr td{ align:left;padding:5px;color:black;background:white; }
</style>
<div class='content'>
<?php
$sql = 'select `name`, `surname` from `players`';
$response = mysqli_query( $dbc, $sql );
if( $response ) {
echo "
<table align='left' cellspacing='5' cellpadding='8' >
<tr>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
</tr>";
while( $row = mysqli_fetch_array( $response ) ) {
echo "
<tr>
<td>{$row['imie']}</td>
<td>{$row['nazwisko']}</td>
</tr>";
}
echo "
</table>";
} else {
printf( 'Couldn\'t issue database query: %s', mysqli_error( $dbc ) );
}
mysqli_close( $dbc );
?>
</div>
There is an open <td> tag in your code you should close it before closing the <tr>
Hi I have a table generated from php, it is editable, I want to save edited values to database. I have no Idea how can I do this as there are many rows(dynamic) on a page.
Here is a screen-shot:-
Please suggest
Edit:-
My code is
echo "<table border='1'>
<tr>
<th>Sl Number</th>
<th>Product Id</th>
<th>Product Name</th>
<th>Product Catagory</th>
<th>Retal Price</th>
<th>Max Price</th>
<th>Min Price</th>
<th>Initial Stock</th>
<th>Quantity Sold</th>
<th>Current Stock</th>
<th>Last Order</th>
<th>Edit/Update</th>
</tr>";
while($row = $result->fetch_assoc())
{
echo "<tr contenteditable>";
echo "<td>" . $row["Row Number"]. "</td>";
echo "<td>" . $row["Product Id"]. "</td>";
echo "<td>" . $row["Product Name"]. "</td>";
echo "<td>" . $row["Product Catagory"]. "</td>";
echo "<td>" . $row["Retal Price"]. "</td>";
echo "<td>" . $row["Max Price"]. "</td>";
echo "<td>" . $row["Min Price"]."</td>";
echo "<td>" . $row["Initial Stock"]."</td>";
echo "<td>" . $row["Quantity Sold"]. "</td>";
echo "<td>" . $row["Current Stock"]."</td>";
echo "<td>" . $row["Last Order"]."</td>";
echo "<td contenteditable = 'false'><button href = '#'>Update</a></td>";
echo "</tr>";
}
Let me give you with the best way
First your database tables have spaces: correct that e.g.
from $row["Initial Stock"] to $row["Initial_Stock"]
Then i will propose you use ajax instead of wasting time clicking buttons
The HTML Page
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<script>
$(function(){
$("#loading").hide();
//acknowledgement message
var message_status = $("#status");
$("td[contenteditable=true]").blur(function(){
var field_userid = $(this).attr("id") ;
var value = $(this).text() ;
$.post('update.php' , field_userid + "=" + value, function(data){
if(data != '')
{
message_status.show();
message_status.text(data);
//hide the message
setTimeout(function(){message_status.hide()},1000);
}
});
});
});
</script>
<style>
table.zebra-style {
font-family:"Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
text-align:left;
border:1px solid #ccc;
margin-bottom:25px;
width:100%
}
table.zebra-style th {
color: #444;
font-size: 13px;
font-weight: normal;
padding: 5px 4px;
}
table.zebra-style td {
color: #777;
padding: 4px;
font-size:13px;
}
table.zebra-style tr.odd {
background:#f2f2f2;
}
#status { padding:10px; position:fixed; top:10px; border-radius:5px; z-index:10000000; background:#88C4FF; color:#000; font-weight:bold; font-size:12px; margin-bottom:10px; display:none; width:100%; }
#loading { padding:10px; position:absolute; top:10px; border-radius:5px; z-index:10000000; background:#F99; color:#000; font-weight:bold; font-size:12px; margin-bottom:10px; display:none; width:100%; }
</style>
<div id="status"> </div>
<div id="loading"></div>
<table id="tableID" border="0" class="sortable table zebra-style">
<thead>
<tr>
<th>Sl Number</th>
<th>Product Id</th>
<th>Product Name</th>
<th>Product Catagory</th>
<th>Retal Price</th>
<th>Max Price</th>
<th>Min Price</th>
<th>Initial Stock</th>
<th>Quantity Sold</th>
<th>Current Stock</th>
<th>Last Order</th>
<th>Edit/Update</th>
</tr>
</thead>
<tbody class="list">
<?php do { ?>
<tr>
<td contenteditable="true" id="Row_Number:<?php echo $row["Row_Number"]; ?>"><?php echo $row["Row_Number"]; ?></td>
<td contenteditable="true" id="Product_Id:<?php echo $row["Product_Id"]; ?>"><?php echo $row["Product_Id"]; ?></td>
<td contenteditable="true" id="Product_Name:<?php echo $row["Product_Name"]; ?>"><?php echo $row["Product_Name"]; ?></td>
<td contenteditable="true" id="Product_Catagory:<?php echo $row["Product Id"]; ?>"><?php echo $row["Product_Catagory"]; ?></td>
<td contenteditable="true" id="Retal_Price:<?php echo $row["Retal_Price"]; ?>"><?php echo $row["Retal_Price"]; ?></td>
<td contenteditable="true" id="Max_Price:<?php echo $row["Max_Price"]; ?>"><?php echo $row["Max_Price"]; ?></td>
<td contenteditable="true" id="Min_Price:<?php echo $row["Min_Price"]; ?>"><?php echo $row["Min_Price"]; ?></td>
<td contenteditable="true" id="Initial_Stock:<?php echo $row["Initial_Stock"]; ?>"><?php echo $row["Initial_Stock"]; ?></td>
<td contenteditable="true" id="Quantity_Sold:<?php echo $row["Quantity_Sold"]; ?>"><?php echo $row["Quantity_Sold"]; ?></td>
<td contenteditable="true" id="Last_Order:<?php echo $row["Last_Order"]; ?>"><?php echo $row["Last_Order"]; ?></td>
<td contenteditable="true" id="Last_Order:<?php echo $row["Last_Order"]; ?>"><?php echo $row["Last_Order"]; ?></td>
<td contenteditable = 'false'></td>";
</tr>
<?php } while($row = $result->fetch_assoc()) ?>
</tbody>
</table>
And the update php page
<?php
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8',
'username',
'password',
array(PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
?>
<?php
if(!empty($_POST))
{
//database settings
foreach($_POST as $field_name => $val)
{
//clean post values
$field_id = strip_tags(trim($field_name));
//from the fieldname:user_id we need to get user_id
$split_data = explode(':', $field_id);
$product_id = $split_data[1];
$field_name = $split_data[0];
if(!empty($product_id) && !empty($field_name) && !empty($val))
{
$affected_rows = $db->exec("UPDATE yourtable SET $field_name = '$val' WHERE product_ID = $product_id");
echo $affected_rows;
echo "Updated";
} else {
echo "Invalid Requests";
}
}
}
else {
echo "Invalid Requests";
}
?>
To save the whole table, you could leave the row-level update buttons out, and have a single save button:
<button id="save">Save</button>
<div id="msg"></div>
The msg area is to display feed-back from the server when the save-operation is performed.
Then you would add this JavaScript to handle the click of the save button:
$('#save').click(function() {
var data = [];
$('td').each(function() {
var row = this.parentElement.rowIndex - 1; // excluding heading
while (row >= data.length) {
data.push([]);
}
data[row].push($(this).text());
});
$.post('savetable.php', {table: data}, function (msg) {
$('#msg').text(msg);
});
});
This will transform the HTML table contents, without header row, to a JavaScript matrix, which then is sent to savetable.php for processing.
In PHP you would then use $_POST['table'] to access that array. When you implement this, first debug, and do a var_dump($_POST['table']) to make sure the data was transferred correctly, and it has the array structure you expect.
Then loop over that array to insert the rows into your database. You can use mysqli or PDO for this.
The PHP script savetable.php should only echo one message: a confirmation ("the table was saved successfully") or an error message ("a problem occurred. Your data was not saved.").
It should not reproduce the HTML of the table, since that is already displayed in the browser. Whatever PHP prints will be used by the JavaScript code to be displayed below the save button.
Here is how savetable.php could look like. But please debug carefully, I did not test this code. And before it works, you first need to set up your database model of course:
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8mb4',
'username', 'password');
// Configure that all database errors result in an exception:
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
// Make a transaction: this allows to rollback any of the changes
// if anything goes wrong before the end of it.
$db->beginTransaction();
// First delete all rows.
$db->exec("DELETE FROM mytable");
// Prepare a statement that will be executed for each row.
// Needs to be extended for all columns:
$stmt = $db->prepare("INSERT INTO mytable (sl_num, product_id, product_name)
VALUES (?, ?, ?)");
foreach ($_POST('table'] as $row) {
$stmt->execute($row); // the columns are passed to the prepared statement.
}
// All went well: commit the changes.
$db->commit();
echo "Table saved successfully";
} catch(PDOException $e) {
// Something went wrong: roll back any changes made
$db->rollback();
echo "An error occurred: " . $e->getMessage();
}
What you can do is ajax call to a php with the id of the row you want to save and the new data. Then use PDO to connect to the database and update the information. After that is done, use javascript to edit the table itself.
So what you need to do is look up how to use ajax calls and use PDO. I suggest when you echo the table itself
<button href = '#' onclick="updateRow('. $row['Row Number'] .')">Update</a></td> where Row Number is the ID in the database and updateRow() is the javascript function you will create to get the new information and send it via ajax. Don't use mysql_*, because it is not supported in php 7 and it will die soon. Look up PDO instead.
I have a html page which links to a php function page, with numerous functions on.
It appears that when the refresh button is clicked in Chrome, the text (only from the functions) disappears. Why would this be caused? This is the same with my update buttons which perform a meta refresh...
function Add_Remove_Topics(){
//CONECT TO MYSQL
$username = "root";
$password = "";
$database = "user_test";
$id = ($_SESSION["user_id"]);
$connect = mysql_connect('localhost',$username,$password);
# mysql_select_db($database) or die( "Unable to select database");
//GET VALUES
$sql = "SELECT * FROM topics";
$result = mysql_query($sql);
//echo "<div id='add-remove-topics'>";
//Table headlines - NOT A PHP
echo "<center>Simply type into the fields to change your current topic information - click update once done editing. If you no longer want one of your topics, click the delete button.</center>";
echo "<form action='' method='POST'><table id='artopics'>
<col width='30%'>
<col width='70%'>
<col width='70px'>
<col width='70px'>
<tr height='40px'>
<td style='background-color: #BD4040; color: white; padding-left: 5px;'>Topic Name</td>
<td style='background-color: #BD4040; color: white; padding-left: 5px;'>Topic Address</td>
<td style='background-color: #BD4040;'></td>
<td style='background-color: #BD4040;'></td>
</tr>";
// output data of each row
while($row = mysql_fetch_assoc($result))
{
echo
"
<tr height='40px'>
<td align='center' style='font-weight: normal;background-color: white;'><input type='text' name='up_topic_name[{$row['topic_id']}]' value='" . $row['topic_name'] . "'></td>
<td align='center' style='font-weight: normal;background-color: white;'><input type='text' name='up_topic_address[{$row['topic_id']}]' value='" . $row['topic_address'] . "'></td>
<td style='background-color: white;' align='center'><button type='submit' name='updateTopic' value='".$row['topic_id']."'>Update</button></td>
<td style='background-color: white;' align='center'><button type='submit' name='deleteTopic' value='".$row['topic_id']."'>Delete</button></td>
</tr>
";
}
if(isset($_POST['updateTopic'])){
$updateID = $_POST['updateTopic'];
$updateTopicName = $_POST['up_topic_name'][$updateID];
$updateTopicAddress = $_POST['up_topic_address'][$updateID];
$updateTopic = mysql_query("UPDATE topics SET topic_name='$updateTopicName', topic_address='$updateTopicAddress' WHERE topic_id='$updateID'") or die(mysql_error());
echo "<meta http-equiv='refresh' content='0'>";
}
if(isset($_POST['deleteTopic'])){
$deleteID = $_POST['deleteTopic'];
$deleteFromTopics = mysql_query("DELETE FROM topics WHERE topic_id = $deleteID ") or die(mysql_error());
$deleteFromUserTopic = mysql_query("DELETE FROM user_topic WHERE topic_id = $deleteID ") or die(mysql_error());
echo "<meta http-equiv='refresh' content='0'>";
}
echo "</table></form>";
echo "<br><center>To add a new topic, simply fill in the fields below, clicking insert once completed.</center>";
echo "<form action='' method='POST'><table id='artopics'>
<col width='30%'>
<col width='70%'>
<col width='140px'>
<tr height='40px'>
<td style='background-color: #BD4040; color: white; padding-left: 5px;'>Topic Name</td>
<td style='background-color: #BD4040; color: white; padding-left: 5px;'>Topic Address</td>
<td style='background-color: #BD4040;'></td>
</tr>";
// output data of each row
echo
"
<tr height='40px'>
<td align='center' style='font-weight: normal;background-color: white;'><input type='text' name='new_topic_name'></td>
<td align='center' style='font-weight: normal;background-color: white;'><input type='text' name='new_topic_address'></td>
<td align='center' style='background-color: white;'><button style='width:130px;' type='submit' name='InsertTopic'>Insert</button></td>
</tr>
";
if(isset($_POST['InsertTopic'])){
$topicName = $_POST['new_topic_name'];
$topicAddress = $_POST['new_topic_address'];
$insertIntoTopics = mysql_query("INSERT INTO topics (topic_name, topic_address) VALUES ('$topicName', '$topicAddress') ") or die(mysql_error());
$grabNewTopicId = mysql_query("SELECT MAX(topic_id) AS topic_id FROM topics") or die(mysql_error());
while($row2 = mysql_fetch_array($grabNewTopicId)) {
$NewTopicId = $row2['topic_id'];
$insertIntoUserTopic = mysql_query("INSERT INTO user_topic (user_id, topic_id) VALUES ('$id', '$NewTopicId') ") or die(mysql_error());
}
echo "<meta http-equiv='refresh' content='0'>";
}
echo "</table></form>";
}
(Screenshots included)
Before refresh/button click
After refresh/button click
Overview
I have some data stored in MySql database related to Products. I am trying to retrieve this data and display it on a page using HTML table.
The PHP and MySql has gone well and all the data is retrieved but it is displayed in a very messy manner.
Here is what I have as a layout:
What I am aiming to achieve is to further divide the results table add more columns rows to make the data more readable
Something like this;
The code: PHP, MySQL & HTML:
<?php
session_start();
include('connect_mysql.php');
$product_name = 'product_name';
$product_qua = 'product_qua';
$product_price = 'product_price';
$product_image = 'product_image';
$product_des = 'product_des';
$sql = mysql_query("SELECT * FROM products");
echo "<table id='display'>";
while($rows = mysql_fetch_array($sql))
{
echo"<br>";
echo"<tr><td>";
echo"$rows[$product_name]<br></td>";
echo"<td><img src=$rows[$product_image] height='200px' width='200px'><br></td>";
echo"<td>Avalible: $rows[$product_qua]<br></td>";
echo"<td>Price: $rows[$product_price]<br></td>";
echo"<td>Description: $rows[$product_des]<br></td>";
echo"</tr>";
}
echo "</table>";
?>
CSS responsible for this part:
#display{
float:left;
border: 5px solid black;
margin-left:100px;
}
just add some padding or a border to the table cells:
table#display td{
border: 1px solid black;
padding:0 8px;
}
Edit: What you could do as well:
<table id='display'>
<?php while($rows = mysql_fetch_array($sql)): ?>
<!-- <br> <- why a break? it's not in the correct spot anyway -->
<tr><td>
<?php echo $rows[$product_name]; ?><br>
</td>
<td> - </td>
<td><img src="<?php echo $rows[$product_image]; ?>" height='200px' width='200px'><br></td>
<td> - </td>
<td>Avalible: <?php echo $rows[$product_qua]; ?><br></td>
<td> - </td>
<td>Price: <?php echo $rows[$product_price]; ?><br></td>
<td> - </td>
<td>Description: <?php echo $rows[$product_des]; ?><br></td>
</tr>
<?php endwhile; ?>
</table>
Tip: I prefer to use the while/endwhile; approach rather than using brackets when displaying data to the user.
First of all don't echo so much HTML using PHP, instead do it like this
<?php
session_start();
include('connect_mysql.php');
$product_name = 'product_name';
$product_qua = 'product_qua';
$product_price = 'product_price';
$product_image = 'product_image';
$product_des = 'product_des';
$sql = mysql_query("SELECT * FROM products"); ?>
<table id='display'>
<?php
while($rows = mysql_fetch_array($sql)) {
?>
<tr><td><?php echo $rows[$product_name]; ?></td>
<!-- And so on-->
<?php
}
?>
</table>
Secondly by seeing your inmage, it seems like you need a border for your table so use
table, td {
border: 1px solid #000000;
}
add the following css to apply border on your table cells:
#display td{ border: 2px solid red; }
and optionally add to your #display { :
border-collapse: collapse;
I'm getting a table appearing after the first result of the nested while loop.
What I'm trying to do is display the usernames as a list by selecting from the "users" table, then comparing that list with the project engineers from the "current projects" table.
This way there is a list of project engineers with their assigned projects underneath their names.
Unfortunately, I'm after the first nested while loop runs, it spits out a empty table and I'm not sure how to get rid of it.
I'm suspecting it has to do with the initial variable of $proj_engineer = "";
Does anyone know where this empty table is coming from and how to get rid of it?
Below is the code:
<?php
$query = mysql_query("SELECT * FROM `users` ORDER BY `username` ASC") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) {
$user_id = $row['user_id'];
$username = $row['username'];
$proj_engineer = "";
$query1 = mysql_query("SELECT * FROM `current_projects` WHERE `proj_engineer`='$username' ORDER BY `proj_engineer` ASC") or die(mysql_error());
while ($row1 = mysql_fetch_assoc($query1)) {
$proj_id = $row1['proj_id'];
$proj_engineer = $row1['proj_engineer'];
}
echo "<table border=1><tr><td colspan=12><p class='bold18'>" . $proj_engineer . "</p></td></tr>";
$query3 = mysql_query("SELECT * FROM `current_projects` WHERE `proj_engineer`='$username' ORDER BY `proj_id` DESC") or die(mysql_error());
while ($row3 = mysql_fetch_assoc($query3)) {
$proj_id = $row3['proj_id'];
$proj_number = $row3['proj_number'];
$proj_name = $row3['proj_name'];
$proj_sort = $row3['proj_sort'];
$proj_start = $row3['proj_start'];
$proj_finish = $row3['proj_finish'];
$proj_overstat = $row3['proj_overstat'];
$proj_dwgstat = $row3['proj_dwgstat'];
$proj_soostat = $row3['proj_soostat'];
$proj_substat = $row3['proj_substat'];
$proj_engineer = $row3['proj_engineer'];
$proj_drafter = $row3['proj_drafter'];
$proj_rating = $row3['proj_rating'];
$proj_pending = $row3['proj_pending'];
$proj_notes = $row3['proj_notes'];
$start_time = date("m/d/y", $proj_start);
$finish_time = date("m/d/y", $proj_finish);
echo "
<tr>
<td width=40>$proj_number</td>
<td width=100>$proj_engineer</td>
<td width=100><a href='./project-page.php?proj_id=$proj_id'>$proj_name</a></td>
<td width=40>$start_time</td>
<td width=40>$finish_time</td>
<td width=110>
<div style='position:relative; background:url(images/bar01.gif); width:$proj_overstat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_overstat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_overstat%</div>
</div>
</td>
<td width=110>
<div style='position:relative; background:url(images/bar02.gif); width:$proj_dwgstat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_dwgstat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_dwgstat%</div>
</div>
</td>
<td width=110>
<div style='position:relative; background:url(images/bar03.gif); width:$proj_soostat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_soostat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_soostat%</div>
</div>
</td>
<td width=110>
<div style='position:relative; background:url(images/bar04.gif); width:$proj_substat; height:20;'>
<div style='position:absolute; bottom:0; left:0; width:$proj_substat; font-weight:bold; color:#000000; vertical-align:middle; height:20; text-align:center;'>$proj_substat%</div>
</div>
</td>
<td width=40 align='center'><a href='project-notes.php?proj_id=$proj_id'><img src='images/note.png' border=0></a></td>
<td width=40 align='center'><a href='./project-edit.php?proj_id=$proj_id'>EDIT</a></td>
<td width=40 align='center'><a href='./project-delete.php?proj_id=$proj_id'>DELETE</a></td>
</tr>
";
}
echo "</table><br>";
}
?>
This might be because, your query: -
$query1 = mysql_query("SELECT * FROM `current_projects` WHERE
`proj_engineer`='$username' ORDER BY `proj_engineer` ASC")
or die(mysql_error());
fetched you an empty value for $proj_engineer. You can do a check before printing your table, whether your variable contains a value instead. Try printing the $proj_engineer before printing the table.
You can enclose your code echoing the table inside an if construct, which will print table only when your value is not empty.