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

How to check if a file is BEING used, i.e. some command is being executed on the data in that file?
Display profile data from database when login
How to integrate laravel packages into an application
Log into a Django project using Magento user database SSO
Image not show in recyclerview from server
php table exporting it to excel [duplicate]
regex not closing span
How to use GroupBy in nested query in Laravel 5?
Laravel Users table Update
Which classes can I type-hint dependencies for automatic injection in Laravel 5?
Urlmanager ignores everything before index.php
Sharing complex objects across controller methods Laravel 5.1
Query optimization for laravel pagination
echo selected in chosen select
Yii 1.1x logs out the user before session timeout
PHP Moving an array into different text files?

Categories

HOME
magento2
applescript
braintree
initialization
celery
mongoid
google-webmaster-tools
elk-stack
material-components
dji-sdk
ag-grid
bellman-ford
graphdb
chromecast
mailmerge
jquery-select2-4
createjs
live-streaming
outlook-restapi
complexity-theory
mailgun
twisted
pywinauto
pinterest
android-5.1.1-lollipop
wsf
adminlte
jest
opam
unity-container
web-analytics
qa
pymongo
rxjs5
substring
chronicle-queue
dragula
crud
android-service
ccavenue
bonita
plantuml
mongoengine
serversocket
cups
text-decorations
grails-spring-security
klee
hdiv
expandablelistview
axis
section508
return-type
node-apn
iptv
sigsegv
scala-collections
streamwriter
svnserve
spring-mongo
mathml
django-redis
openmrs
cryptojs
android-mapview
directx-9
algebraixlib
ampersand
findersync
google-hangouts
famo.us
symja
zend-mail
inputbox
visual-c++-2012
android-2.3-gingerbread
csslint
hyperloglog
rails-api
refit
jomsocial
eclim
virtual-channel
libxml-js
pacman
dynamic-rdlc-generation
arrow
getopt-long
thejit
jdom
struts2-s2hibernate
monocross
opends
algol68
wiktionary
multidrop-bus
radscheduler
nsrangeexception
mediacontroller
tablet-pc
ccnet-config
outlook-2007-addin
mysqli-multi-query
subtext
inversion
tso

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