/    Sign up×
Community /Pin to ProfileBookmark

Displaying array in HTML table

Hi all,

Please could somebody point out where I’m going wrong with this?

I’m trying to display some results in a HTML table but I can’t get them to show.

[code=php]<table class=”table table-bordered table-hover table-striped”>
“<thead>
<tr>
<th>Company Name</th>
<th>Firstname</th>
<th>Lastname</th>
<th>E-mail</th>
<th>Address Line</th>
<th>Address Line</th>
<th>City/Town</th>
<th>County</th>
<th>Postcode</th>
<th>Country</th>
<th>Phone Number</th>
<th>Update Details</th>
<th>Equipment</th>
</tr>
</thead>”;
<?php while($row = mysqli_fetch_array($result)); ?>
<tbody>
<tr>
<?php echo “<td>” . $row[‘companyid’] . “</td>”; ?>
<?php echo “<td>” . $row[‘companyname’] . “</td>”; ?>
<?php echo “<td>” . $row[‘firstname’] . “</td>”; ?>
<?php echo “<td>” . $row[‘lastname’] . “</td>”; ?>
<?php echo “<td>” . $row[’email’] . “</td>”; ?>
<?php echo “<td>” . $row[‘address1’] . “</td>”; ?>
<?php echo “<td>” . $row[‘address2’] . “</td>”; ?>
<?php echo “<td>” . $row[‘city’] . “</td>”; ?>
<?php echo “<td>” . $row[‘county’] . “</td>”; ?>
<?php echo “<td>” . $row[‘postcode’] . “</td>”; ?>
<?php echo “<td>” . $row[‘country’] . “</td>”; ?>
<?php echo “<td>” . $row[‘phonenumber’] . “</td>”; ?>
</tr>
</tbody>
</table>[/code]

What am I missing? 😮

Thanks

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJan 21.2015 — The code you posted is missing some parts. It starts without a quote and then starts using quotes on the next html tag. What gives? How about a little more context here?
Copy linkTweet thisAlerts:
@heyjimauthorJan 21.2015 — The code you posted is missing some parts. It starts without a quote and then starts using quotes on the next html tag. What gives? How about a little more context here?[/QUOTE]

Ahh, sorry, I was trying a few things and hadn't removed everything. Here's the full page:

[code=php]<?php
include("includes/error_check.php");
include("includes/db_config.php");
include("includes/check_sql.php");

//Gets the ID string from the URL
$companyid = isset($_GET['companyid']) ? mysqli_real_escape_string($con, $_GET['companyid']) : '';

//SQL statement
$result = mysqli_query($con,"SELECT * FROM tbl_customers WHERE companyid='$companyid'");
?>

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>Customers</title>

</head>

<body>

<div id="wrapper">

<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand"><img src="img/seriun.png">
</div>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<?php include('includes/main_nav.php');?>
<!-- /.navbar-collapse -->
</nav>

<div id="page-wrapper">

<div class="container-fluid">

<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Customers
</h1>
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Company Name</th>
<th>Firstname</th>
<th>Lastname</th>
<th>E-mail</th>
<th>Address Line</th>
<th>Address Line</th>
<th>City/Town</th>
<th>County</th>
<th>Postcode</th>
<th>Country</th>
<th>Phone Number</th>
<th>Update Details</th>
<th>Equipment</th>
</tr>
</thead>
<?php while($row = mysqli_fetch_array($result)); ?>
<tbody>
<tr>
<?php echo "<td>" . $row['companyid'] . "</td>"; ?>
<?php echo "<td>" . $row['companyname'] . "</td>"; ?>
<?php echo "<td>" . $row['firstname'] . "</td>"; ?>
<?php echo "<td>" . $row['lastname'] . "</td>"; ?>
<?php echo "<td>" . $row['email'] . "</td>"; ?>
<?php echo "<td>" . $row['address1'] . "</td>"; ?>
<?php echo "<td>" . $row['address2'] . "</td>"; ?>
<?php echo "<td>" . $row['city'] . "</td>"; ?>
<?php echo "<td>" . $row['county'] . "</td>"; ?>
<?php echo "<td>" . $row['postcode'] . "</td>"; ?>
<?php echo "<td>" . $row['country'] . "</td>"; ?>
<?php echo "<td>" . $row['phonenumber'] . "</td>"; ?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- /.row -->

</div>
<!-- /.container-fluid -->

</div>
<!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="js/jquery.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>

</body>

</html>
[/code]


So, you'll see the SQL query at the top which works but when I try and format the results into the table, it doesn't display anything.
Copy linkTweet thisAlerts:
@ginerjmJan 21.2015 — Sloppy coding style but the real problem is the semi at the end of your while. Also - you probably need {} to group all the code you want in the while loop.
Copy linkTweet thisAlerts:
@ginerjmJan 22.2015 — Try this in place of your current code:
<i>
</i>..
..
..
&lt;tbody&gt;
&lt;?php
while($row = mysqli_fetch_array($result))
{
echo "&lt;tr&gt;";
echo "&lt;td&gt;{$row['companyid']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['companyname']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['firstname']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['lastname']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['email']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['address1']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['address2']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['city']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['county']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['postcode']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['country']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['phonenumber']}&lt;/td&gt;";
echo "&lt;/tr&gt;";
}
?&gt;
&lt;!-- back in html --&gt;
&lt;/tbody&gt;
&lt;/table&gt;
..
..
..


Much simpler than what you put together, no?
Copy linkTweet thisAlerts:
@heyjimauthorJan 22.2015 — Try this in place of your current code:
<i>
</i>..
..
..
&lt;tbody&gt;
&lt;?php
while($row = mysqli_fetch_array($result))
{
echo "&lt;tr&gt;";
echo "&lt;td&gt;{$row['companyid']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['companyname']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['firstname']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['lastname']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['email']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['address1']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['address2']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['city']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['county']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['postcode']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['country']}&lt;/td&gt;";
echo "&lt;td&gt;{$row['phonenumber']}&lt;/td&gt;";
echo "&lt;/tr&gt;";
}
?&gt;
&lt;!-- back in html --&gt;
&lt;/tbody&gt;
&lt;/table&gt;
..
..
..


Much simpler than what you put together, no?[/QUOTE]


That works fine, thanks for the help, much appreciated!
Copy linkTweet thisAlerts:
@ginerjmJan 22.2015 — HTH. As long as you see how and why it works. And stop putting ; at the end of while statements.
Copy linkTweet thisAlerts:
@heyjimauthorJan 24.2015 — HTH. As long as you see how and why it works. And stop putting ; at the end of while statements.[/QUOTE]

Yep, now I see it I can see what's going on, thanks a lot!
×

Success!

Help @heyjim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...