codeigniter


CodeIgniter Database result align not proper


I got the result from database and trying to display on page. but alignment is not correct. may i know how can i fix it?
Code in View
<?php
echo "<table align='center'>";
echo "<tr>";
echo "<td> Language ID: </td>";
echo "</tr>";
echo "<tr>";
echo "<td> Language Name: </td>";
echo "</tr>";
echo "<tr>";
echo "<td> Date Posted : </td>";
echo "</tr>";
if ($query == true) {
foreach ($query as $row) {
echo "<tr>";
echo "<td>" . $row -> pk_bint_language_id . "</td>";
echo "<td>" . $row -> vchr_language_name . "</td>";
echo "<td>" . $row -> bint_language_level . "</td>";
echo "<td>" . $row -> dat_updated_date . "</td>";
echo "</tr>";
}
}
echo "</table>";
?>
Output:
You want to display four rows within the foreach loop, however you have only three in the header section. From what I can see you are missing Language level /added to the example/
echo "<table align='center'>
<tr>
<td> Language ID: </td>
<td> Language Name: </td>
<td> Language Level: </td>
<td> Date Posted : </td>
</tr>";
if ($query == true) {
foreach ($query as $row) {
echo "<tr>";
echo "<td>" . $row -> pk_bint_language_id . "</td>";
echo "<td>" . $row -> vchr_language_name . "</td>";
echo "<td>" . $row -> bint_language_level . "</td>";
echo "<td>" . $row -> dat_updated_date . "</td>";
echo "</tr>";
}
}
echo "</table>";
You seem to have 3 <td>s in the first table row (<tr>) with the static "Language ID:" and such, but you have 4 <td>s inside the foreach() loop. It seems like you are missing the "Language level" from the static <td>s.
I would recommend to use the <thead> and <tbody> tags as well.
you should use table header th instead of td. At least it is a more proper way.
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
You can check that on w3school http://www.w3schools.com/html/html_tables.asp
#bborisovs answer is correct . But if you want to use 3 td instead of four you can also do like this
<td colspan="2"> //meainng this single 'td' with take two 'td' place

Related Links

what is question mark means in the url in php codeigniter framework
CodeIgniter - Load language globally (not by file but by folder)
How to Integrate Recurring payment using Barclaycard in Codeigniter?
Server error 500 in codeigniter
How to Verify Email to see if it is exist in Code Igniter?
when I use If isset($_FILES['something'] I can't access my controller array in my view in codeigniter?
Unable to load the requested class Session in Codeigniter
resetting password in codeigniter
having trouble in join query in codeigniter
How to host a website with CodeIgniter on a server?
codeigniter Trying to get property of non-object
Codeigniter - Call to undefined function set_value()
Is it dbase is support on Codeigniter 3?
how to configure codeigniter hmvc in subdomain
Use like in join in codeigniter
Why does not work routing with regular expression in Codeigniter?

Categories

HOME
ios
elastic-beanstalk
asp.net-mvc
web-applications
clojure
identityserver4
elf
appium-ios
haskell-stack
api.ai
jasypt
android-bluetooth
whitespace
jfreechart
stm
librsvg
cross-compiling
cobol
frequency
asp.net-mvc-5.2
ssrs-tablix
jgit
web-audio
org-mode
drupal-commerce
gas
contains
jruby
windows-applications
sencha-touch-2
mediator
iteration
epicorerp
smallbasic
parallax
point-cloud-library
laravel-valet
reformatting
shinydashboard
kprobe
ruamel.yaml
akka-http
google-domain-api
data-science
dsx
hawkular
mergesort
qmenubar
virtualmin
autofocus
arm7
federation
canopen
mashery
infiniband
masm32
master-data-management
nuget-package-restore
sqlite-net
android-alertdialog
hard-drive-failure
pygments
rsh
namenode
jca
multiple-files
uac
samsung-gear
materialdrawer
ospf
interpreted-language
spl
spinach
mailx
openxls
lossless-compression
directcompute
css3pie
android-c2dm
antisamy
junit-runner
preon
fay
resolver
semantic-markup
mms-gateway
capitalize
argumentexception
speaker
hogan.js
layout-manager
applaud
zmodem
boost-gil
demoscene
eye-detection
xoom
wmd

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App