php


Data table error


Im using a datatable to show records from a DB, using PHP.
See my code below;
<table class="table datatable-basic">
<thead>
<tr>
<th> ID </th>
<th> Name</th>
<th>Address </th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<?
$result9023=mysql_query("SELECT * FROM hr_locations")or die('ERROR 315' );
$num_rows = mysql_num_rows($result9023);
for ($i = 1; $i <= mysql_num_rows($result9023); $i++) {
$row = mysql_fetch_array($result9023);
$location_id = $row ['id'];
$name = $row ['location'];
$address = $row ['address'];
echo " <tr>
<td>$location_id</td>
<td>$name</td>
<td>$address</td>
<td class='text-center'>Edit</td>
</tr>
"; } ?>
</tbody>
</table>
The table is showing correctly, with the data populated as it should however I am getting the below error when the page loads.
I have looked at https://datatables.net/tn/4 however it's not making much sense?
Since most MySQL array start with 0 do this:
for ($i = 0; $i < $num_rows; $i++) {
Set $i = 0 then state that $i must be less than the number of rows (if you have 4 you will get 0,1,2,3 (4 rows, properly indexed). Instead of counting the rows again, just use the variable you already set for the count.
You're actually probably doing a little too much with your code. Instead of using an unnecessary for loop, just use a while:
while($row = mysql_fetch_array($result9023)){
$location_id = $row ['id'];
$name = $row ['location'];
$address = $row ['address'];
echo " <tr>
<td>$location_id</td>
<td>$name</td>
<td>$address</td>
<td class='text-center'>Edit</td>
</tr>
"; } ?>
This way you're making sure to catch each row returned from your query without possibly duplicating or skipping rows as you might do when using a for loop along with mysql_fetch_array() as you're trying to do.

Related Links

Problems Parsing JSON from PHP
How to match and replace in a mouthful with PHP?
Is there any API to get Train details of US Railway Service [closed]
Maximum time limit Error in php
How to redirect all web traffic to a specific page?
Is it possible to create an IM chatting service on the cloud?
What are the best free CASE tools for PHP? [closed]
Why doesn't my parent process wait for its child to finish executing?
CakePHP authentication breaking after an incorrect login
Make Apache wait longer before delivering HTTP 408 request timeout
PHP session save_handler user (mysql) won't save
php random name
Seamless SSO authenticating against Active Directory
Get fields in a PDF file using PHP
PHP parsing on includes
count() causing “unexpected T_STRING” error?

Categories

HOME
hpoo
webview
ios-simulator
portable-class-library
liferay-7
iptables
flurry
mosquitto
gprs
eddystone
log4j2
siesta
mpu6050
pickle
infrared
backtracking
restier
software-packaging
dragula
openbravo
history.js
acrobat
amazon-cloudtrail
materialize
jsonresult
copy-protection
source-insight
toad
python-2.x
quick-nimble
delayed-job
om-next
counting
jfxtras
jslint
code-rally
cloudera-quickstart-vm
assert
stat
ejml
apache-toree
bit-shift
return-type
aws-kinesis-firehose
libreoffice-writer
photoswipe
brightscript
openstack-glance
spring.net
test-data
msxml
fitbit
mathjs
nunit-console
coovachilli
ajaxmin
openmrs
html.actionlink
fantom
embeddedwebserver
org-babel
password-recovery
vs-unit-testing-framework
dc
adwords-apiv201402
xhprof
jquery-mobile-flipswitch
fileshare
cidr
jack
gpu-programming
ctp
visual-c++-2005
saga
coalesce
ax
acceptance-testing
dynamic-rdlc-generation
system-information
firebird1.5
kolite
expression-web
page-curl
qcar-sdk
libxslt
downgrade
tessellation
ixmldomdocument
zend-test
html-components
google-translator-toolkit
source-code-protection
downcasting
xap
sqlsitemapprovider
index.dat
comment-conventions
jvm-bytecode

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App