My view attendance table not pulling table from Database - php

When I attempt to view an attendance that was already filled, it brings up the table, but it is empty. My SQL and Apache error logs do not give any errors and as far as im concerned, the database table names do match.
This is my PHP code for the View All. I've also tried defining $date=date("Y-m-d); before the mysqli_query and changing the "where date=$_POST[date]" to "date=$date" but to no avail
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<form action="AttendanceTable.php" method="post">
<table class="table table-striped">
<tr>
<th>#serial Number</th> <th>Student Name</th> <th>Roll Numbers</th> <th>Attendance Status</th>
</tr>
<?php
$result=mysqli_query($con, "select * from attendance_records where date=$_POST[date]");
$serialnumber=0;
$counter=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['student_name']; ?>
</td>
<td> <?php echo $row['roll_number']; ?> </td>
<td>
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Present"> Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" value="Absent"> Absent
</td>
</tr>
<?php
$counter++;
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>
This is my PHP code for the page before the view attendance
<?php
include("includes/dbhA.inc.php");
include("includes/PresenceRoster.inc.php");
?>
<div class="panel panel-default">
<div class="panel panel-heading">
<h2>
<a class="btn btn-success" href="Add.php"> Add Students </a>
<a class="btn btn-info pull-right" href="AttendanceTable.php"> Back </a>
</h2>
<div class="panel panel-body">
<table class="table table-striped">
<tr>
<th>Serial Number</th> <th>Dates</th> <th>Show Attendance</th>
</tr>
<?php
$result=mysqli_query($con, "SELECT distinct date FROM attendance_records");
$serialnumber=0;
while($row=mysqli_fetch_array($result))
{
$serialnumber++;
?>
<tr>
<td> <?php echo $serialnumber; ?> </td>
<td> <?php echo $row['date']; ?> </td>
<td>
<form action="show_attendance.php" method="POST">
<input type="hidden" value="<?php echo $row['date'] ?>" name="date">
<input type="submit" value="Show Attendance" class="btn btn-primary">
</form>
</td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="Submit" class="btn btn-primary">
</form>
</div>
</div>

You don't have any quotes, so your WHERE condition
where date=$_POST[date]
is expanded to where date=2019-02-17. MySQL happily computes 2019 - 2 - 17 = 2000. No date matches that so you get back zero records.
You should use a prepared statement for queries that take parameters like this, that way the database adds the necessary quotes and escape sequences http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

Related

Could anyone help me to know how to make this to work?

I would like to output data in the different tag on call but nothing seems to work, I really dont know what i am doing wrong, could anyone help me?
it displays "Illegal string offset 'patient' in" in all the
PS: I am a beginner to php and mysql. I have edited my code and figured out some errors and I have now noticed that the error is thrown at line 73 on my foreach loop "Warning: Invalid argument supplied for foreach()"
<?php include"../Include/header.php";?>
<?php include"../Include/sidebar.php";?>
<?php
include("../inc/connect.php") ;
$db_connect =mysqli_connect("localhost","root","","clinic_management");
$s="SELECT * FROM addappointment WHERE `app_date` = '".date('Y-m-d')."'";
$query=mysqli_query($db_connect, $s)or die (mysql_error($db_connect));
$row1=mysql_fetch_all($query);
function mysql_fetch_all($query)
{
$temp='';
$all = array();
while ($all[] = mysqli_fetch_assoc($query)) {$temp=$all;}
return $temp;
// print_r($numrows);echo "string"; exit();
}
?>
<div class="content-wrapper">
<section class="content-header">
<h1>
Today's Appointment
<small></small>
</h1>
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i> Home</li>
<li class="active">Today's Appointment
</li>
</ol>
</section>
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<i class="fa fa-user"></i> <h3 class="box-title"> Today's Appointment</h3>
</div>
<button type="submit" name="submit" class="btn btn-success bg-blue"><i class="fa fa-plus-square"></i> Add Appointment</button><br>
<!-- <td>
<button type="button" class="btn btn-default">Copy</button>
</td> -->
<td>
<button type="button" class="btn btn-default">Excel</button>
</td>
<td>
<button type="button" class="btn btn-default">CSV</button>
</td>
<td>
<button type="button" class="btn btn-default">PDF</button>
</td>
<td>
<button type="button" onclick="window.print();" class="btn btn-default">Print</button>
</td>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th> id </th>
<th> Patient </th>
<th> Date </th>
<th> Start Time </th>
<th> End Time </th>
<th> Remark </th>
<th> Option </th>
</tr>
</thead>
<tbody>
<?php
foreach($row1 as $row)
{
$sql1=" SELECT name FROM patientregister WHERE id='".$row['patient']."'";
$write1 =mysqli_query($db_connect, $sql1) or die(mysqli_error($db_connect));
//print_r($sql); exit;
$row2=mysqli_fetch_array($write1)or die (mysqli_error($db_connect));
//print_r($row2); echo $row2['name']; exit;
//echo "$description"; exit();
//print_r($row1); exit;
//echo "$description"; exit();
?> <tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['app_date'];?></td>
<td><?php echo $row['starttime'];?></td>
<td><?php echo $row['endtime'];?></td>
<td><?php echo $row['remark'];?></td>
<td><span class="btn btn-danger"><i class="fa fa-trash-o"></i> Delete</span></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
</div>
<?php include "../Include/footer.php";?>
If the query doesn't return any rows, mysql_fetch_all() will return an empty string instead of an empty array, because you initialize $temp to a string.
There's no need for the $temp variable in the first place, you can just return $all.
function mysql_fetch_all($query)
{
$all = array();
while ($all[] = mysqli_fetch_assoc($query)) {}
return $all;
}
Also, if you have the MSYQLND driver, there's a built-in mysqli_fetch_all() function, you don't need to write your own.

How to loop through all the records in jquery datatable in php

I have JQUERY datatable in my PHP page in which I have one check box, I want to get the values of all the check boxes checked in that datatable with php code by using
implode(',',$_POST['accessflag']);
But it is showing the values only on the current page. I want to get the values of all checked check boxes in the datatable from all the pages of that particular table .anybody please help me to get this done.
my HTML code is
<div class="row control-container pt-2">
<div class="table-responsive col-md-12">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php if (isset($_SESSION['SaveMsg'])) { echo $_SESSION['$SaveMsg'];unset($_SESSION['$SaveMsg']);}?>
</label>
</div>
</div>
<table id="moduletable" class="table table-sm table-bordered table-hover table-lightfont display">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GMA_ACCESS_FLAG"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","OPTIONS"); ?></th>
</tr>
</thead>
<tbody>
<?php
if(isset($_SESSION['$nextset'])){
$limit=$_SESSION['$nextset'];}
else{$limit=0;}
if ($_SESSION['$language']="E") {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_desc,gma_module_id,module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id LIMIT ".$limit.",50");
}
else {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_bldesc as grp_desc,gma_module_id,module_blname as module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id LIMIT ".$limit.",50");
}
foreach ($groupdata as $groupdatalist) {?>
<tr>
<td><?php echo $groupdatalist["grp_desc"];?></td>
<td><?php echo $groupdatalist["module_name"];?></td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<td style="text-align:right;width:10px;"><input type="checkbox" name="accessflag[]" id="accessflag"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php else:?>
<td style="text-align:right;width:10px;"><input type="checkbox" checked name="accessflag[]" id="accessflag" width="10px"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php endif;?>
<!--<td style="display:none;"><//?php echo $groupdatalist["gma_grp_id"];?></td>
<td style="display:none;"><//?php echo $groupdatalist["gma_module_id"];?></td>
<td style="display:none;"><input type="text" name="gmaid" id="gmaid" value="<//?php echo $groupdatalist["gma_id"];?>"></td>-->
<td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<a href="#" class="btn btn-light btn-sm pt-0 shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
<?php else:?>
<a href="group_action.php?gmagrpid=<?php echo $groupdatalist['gma_grp_id']?>&gmamoduleid=<?php echo $groupdatalist['gma_module_id']?>&page=MenuPermission&gmagrpdesc=<?php echo $groupdatalist['grp_desc']?>&gmamodulename=<?php echo $groupdatalist['module_name']?>" class="btn btn-light btn-sm pt-0 shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
<?php endif;?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" name="updmodaccess" formnovalidate class="btn nc btn-primary btn-rounded">
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
PHP code on updmodaccess button is
if (isset($_POST['updmodaccess'])) {
$keytoupdate=implode(',',$_POST['accessflag']);
$table="group_module_access"; $data=array("gma_access_flag"=>"Y", "gma_upd_dt"=>GetDateTime($_SESSION['$TimeZone']), "gma_upd_uid"=>"{$_SESSION['$userid']}");
UpdateData($table,$data,"gma_id in (".$keytoupdate.")",$Message,$flg);
$data=array("gma_access_flag"=>"N", "gma_upd_dt"=>GetDateTime($_SESSION['$TimeZone']), "gma_upd_uid"=>"{$_SESSION['$userid']}");
UpdateData($table,$data,"gma_id not in (".$keytoupdate.")",$Message,$flag);
}
you can try the following code. I hope it helps.
you need to get these values using ajax and then need to send this value to php using an ajax.
$(document).ready(function(){
var data = new Object();
var table = $('#addUsersToAboTable').DataTable();
$('#addUsersToAboTable').on('change', ':checkbox', function () {
data[table.row($(this).parents('tr').get(0)).index()] = this.checked;
});
$('#getDataBtn').on('click',function(){
console.log(data);
});
});
Here you can see the demo script as well jQuery Datatables, How to get all selected checkboxes from EVERY page

Fatal error: Uncaught Error: Unsupported operand types

I need your help please. I got an error about "Unsupported operand types" but i didn't know about it. i've been trying search on google but i'm still can't fix it.
this my error title :
Fatal error: Uncaught Error: Unsupported operand types in
/Applications/XAMPP/xamppfiles/htdocs/aplikasi_penjualan/admin/barang.php:28
Stack trace: #0 {main} thrown in
/Applications/XAMPP/xamppfiles/htdocs/aplikasi_penjualan/admin/barang.php
on line 28
This is code at line 28 : $halaman= ceil($jum / $per_hal);
and this my code :
<?php include 'header.php'; ?>
<h3><span class="glyphicon glyphicon-briefcase"></span> Data Barang</h3>
<button style="margin-bottom:20px" data-toggle="modal" data-target="#myModal" class="btn btn-info col-md-2"><span class="glyphicon glyphicon-plus"></span>Tambah Barang</button>
<br/>
<br/>
<?php
$periksa=mysqli_query($conn, "select * from barang where jumlah <=3");
while($q=mysqli_fetch_array($periksa)){
if($q['jumlah']<=3){
?>
<script>
$(document).ready(function(){
$('#pesan_sedia').css("color","red");
$('#pesan_sedia').append("<span class='glyphicon glyphicon-asterisk'></span>");
});
</script>
<?php
echo "<div style='padding:5px' class='alert alert-warning'><span class='glyphicon glyphicon-info-sign'></span> Stok <a style='color:red'>". $q['nama']."</a> yang tersisa sudah kurang dari 3 . silahkan pesan lagi !!</div>";
}
}
?>
<?php
$per_hal=10;
$jumlah_record=mysqli_query($conn, "SELECT COUNT(*) from barang");
$jum=mysqli_fetch_array($jumlah_record);
$halaman= ceil($jum / $per_hal); //-----> THE ERROR IN HERE
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_hal;
?>
<div class="col-md-12">
<table class="col-md-2">
<tr>
<td>Jumlah Record</td>
<td><?php echo $jum; ?></td>
</tr>
<tr>
<td>Jumlah Halaman</td>
<td><?php echo $halaman; ?></td>
</tr>
</table>
<a style="margin-bottom:10px" href="lap_barang.php" target="_blank" class="btn btn-default pull-right"><span class='glyphicon glyphicon-print'></span> Cetak</a>
</div>
<form action="cari_act.php" method="get">
<div class="input-group col-md-5 col-md-offset-7">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-search"></span></span>
<input type="text" class="form-control" placeholder="Cari barang di sini .." aria-describedby="basic-addon1" name="cari">
</div>
</form>
<br/>
<table class="table table-hover">
<tr>
<th class="col-md-1">No</th>
<th class="col-md-4">Nama Barang</th>
<th class="col-md-3">Harga Jual</th>
<th class="col-md-1">Jumlah</th>
<!-- <th class="col-md-1">Sisa</th> -->
<th class="col-md-3">Opsi</th>
</tr>
<?php
if(isset($_GET['cari'])){
$cari=mysqli_real_escape_string($_GET['cari']);
$brg=mysqli_query($conn, "select * from barang where nama like '$cari' or jenis like '$cari'");
}else{
$brg=mysqli_query($conn, "select * from barang limit $start, $per_hal");
}
$no=1;
while($b=mysqli_fetch_array($brg)){
?>
<tr>
<td><?php echo $no++ ?></td>
<td><?php echo $b['nama'] ?></td>
<td>Rp.<?php echo number_format($b['harga']) ?>,-</td>
<td><?php echo $b['jumlah'] ?></td>
<td>
Detail
Edit
<a onclick="if(confirm('Apakah anda yakin ingin menghapus data ini ??')){ location.href='hapus.php?id=<?php echo $b['id']; ?>' }" class="btn btn-danger">Hapus</a>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4">Total Modal</td>
<td>
<?php
$x=mysqli_query($conn, "select sum(modal) as total from barang");
$xx=mysqli_fetch_array($x);
echo "<b> Rp.". number_format($xx['total']).",-</b>";
?>
</td>
</tr>
</table>
<ul class="pagination">
<?php
for($x=1;$x<=$halaman;$x++){
?>
<li><?php echo $x ?></li>
<?php
}
?>
</ul>
<!-- modal input -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Tambah Barang Baru</h4>
</div>
<div class="modal-body">
<form action="tmb_brg_act.php" method="post">
<div class="form-group">
<label>Nama Barang</label>
<input name="nama" type="text" class="form-control" placeholder="Nama Barang ..">
</div>
<div class="form-group">
<label>Jenis</label>
<input name="jenis" type="text" class="form-control" placeholder="Jenis Barang ..">
</div>
<div class="form-group">
<label>Suplier</label>
<input name="suplier" type="text" class="form-control" placeholder="Suplier ..">
</div>
<div class="form-group">
<label>Harga Modal</label>
<input name="modal" type="text" class="form-control" placeholder="Modal per unit">
</div>
<div class="form-group">
<label>Harga Jual</label>
<input name="harga" type="text" class="form-control" placeholder="Harga Jual per unit">
</div>
<div class="form-group">
<label>Jumlah</label>
<input name="jumlah" type="text" class="form-control" placeholder="Jumlah">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
<input type="submit" class="btn btn-primary" value="Simpan">
</div>
</form>
</div>
</div>
</div>
<?php
include 'footer.php';
?>
I Hope you can help me.. Thanks a lot.
On line 28, you fetch the result as an array (see the doc for mysqli_fetch_array )
$jum=mysqli_fetch_array($jumlah_record); so $jum is array and cannot be divided
You can try this :
$per_hal=10;
$jumlah_record=mysqli_query($conn, "SELECT COUNT(*) as number from barang");
$jum=mysqli_fetch_array($jumlah_record);
$halaman= ceil($jum['number'] / $per_hal);
$halaman= ceil($jum / $per_hal); was replaced by $halaman= ceil($jum['number'] / $per_hal); to get the value returned by the query

cart button not working

Hi I have some more issues in my coding.when i have to changed my coding structure from div to table add to cart button not working.when it is working when it is in div but i have change to table cart button not working please help me to resolve my issue..
Code below is the old one (div) thats working fine here..
<?php if($microproduct['nr']){?>
<div class="product-box">
<div class="list" id="micropro">
<?php foreach ($microproduct['result'] as $resultmicroproduct){ ?>
<div class="row">
<div class="col-md-3">
<img src="images/feature-two-one.png" class="img-fluid mx-auto d-block">
</div>
<div class="col-md-7">
<div class="pro-desc">
<h5><?php echo $conn->stripval($resultmicroproduct['microsoft_product_legalname']);?></h5>
<p>Part number: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_partnumber']);?></p>
<p>Item Name: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_name']);?></p>
<p>Product family: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_family']);?></p>
<h4><i class="fa fa-rupee"></i> <?php echo $conn->stripval($resultmicroproduct['microsoft_product_price']);?></h4>
</div>
</div>
<div class="col-md-2">
<div class="wrapper-div">
<input min="1" type="number" name="quantity<?php echo $resultmicroproduct['microsoft_product_id'] ?>" class="form-control" id="quantity" value="1" autocomplete="off">
<br>
<?php $postvalue = base64_encode(json_encode($resultmicroproduct)); ?>
<input type="hidden" name="type" value="microsoft_product">
<button class="btn btn-dark btn-sm add_to_cart" id="<?php echo $resultmicroproduct['microsoft_product_id'] ?>" >Add to Cart</button>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
Code Below is the new one (table) cart button not working..
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Image</th>
<th>Product Description</th>
<th>Quantity & Cart</th>
</tr>
</thead>
<?php if($microproduct['nr']){?>
<tbody>
<?php foreach ($microproduct['result'] as $resultmicroproduct){ ?>
<tr class="product-box">
<td><img src="images/feature-two-one.png" class="img-fluid mx-auto d-block"></td>
<td>
<div class="pro-desc">
<h5><?php echo $conn->stripval($resultmicroproduct['microsoft_product_legalname']);?></h5>
<p>Part number: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_partnumber']);?></p>
<p>Item Name: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_name']);?></p>
<p>Product family: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_family']);?></p>
<h4><i class="fa fa-rupee"></i> <?php echo $conn->stripval($resultmicroproduct['microsoft_product_price']);?></h4>
</div>
</td>
<td>
<div class="wrapper-div">
<input min="1" type="number" name="quantity<?php echo $resultmicroproduct['microsoft_product_id'] ?>" class="form-control" id="quantity" value="1" autocomplete="off">
<br>
<input type="hidden" name="type" value="microsoft_product">
<button class="btn btn-dark btn-sm add_to_cart" id="<?php echo $resultmicroproduct['microsoft_product_id'] ?>">Add to Cart</button>
</div>
</td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
<tfoot>
<th>Image</th>
<th>Product Description</th>
<th>Quantity & Cart</th>
</tfoot>
</table>
You don't even have a form.
<form action ="?" method="?">
//your inputs and submit
</form>
What do you expect to happen if you don't define what to do?

Display specific row data in bootstrap modal with edit button click

I am new to programming and trying to implement bootstrap modal to display row data from a mysql table into the modal window.
I have tried the solution found on stackoverflow "Pull information from mysql table to bootstrap modal to edit" by link. But could not able to display the particular row with the $row['SFID'].
I can pull table data but when I click the edit button in front of any row it always show the last row id
and doesn't display the data in the input box on the modal to edit the data???.
Here I am till now, Please help me out.
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>SFID</th>
<th>Company</th>
<th>Product</th>
<th>Product Line</th>
<th>Dealer Class</th>
<th>Status</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM tblcustomer";
$stmt = $db->prepare($query);
$stmt->execute();
foreach ($stmt as $row): ?>
<tr>
<?php $rowID = $row['SFID']; ?>
<td><?php echo $row['SFID']; ?></td>
<td><?php echo $row['CompanyName']; ?></td>
<td><?php echo $row['Product']; ?></td>
<td><?php echo $row['ProductLine']; ?></td>
<td><?php echo $row['DealerClass']; ?></td>
<td><?php echo $row['RequestStatus']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<?php echo "<a class='btn update' href='#editModal' data-sfid='".$row['SFID']."' role='button' data-toggle='modal'>Edit</a>"; ?>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</table>
<div id="editModal" class="modal hide fade in" style="display: none; ">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit Customer Details</h3>
</div>
<div>
<form class="contact">
<fieldset>
<div class="modal-body">
<?php echo $row['SFID']; ?>
<ul class="nav nav-list">
<li class="nav-header">SFID</li>
<li><input class="input-xlarge" type="text" name="mysfid" id="mysfid"></li>
<!--<li class="nav-header">Company</li>
<li><input class="input-xlarge" value=" " type="text" name="mycompany"></li>
<li class="nav-header">Dealer Class</li>
<li><input class="input-xlarge" value=" " type="text" name="mydealerclass"></li> -->
</ul>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Approved</button>
Close
</div>
</div>
<script>
$(document).ready(function(){
$('a.edit').click(function(){
var sfid = $(this).data('sfid');
var company = $(this).data('company');
var dealerclass = $(this).data('dealerclass');
$('#mysfid').val(sfid);
$('#mycompany').val(company);
$('#mydealerclass').val(dealerclass);
});
});
</script>
Thanks for your help.
<table class="table table-bordered" width="100%">
<thead>
<tr>
<th>SFID</th>
<th>Company</th>
<th>Product</th>
<th>Product Line</th>
<th>Dealer Class</th>
<th>Status</th>
</tr>
</thead>
<?php
$query = "SELECT * FROM tblcustomer";
$result = mysql_query($query);
$i=1;
while($row = mysql_fetch_assoc($result))
{
?>
<tr>
<?php $rowID = $row['SFID']; ?>
<td><?php echo $row['SFID']; ?></td>
<td><?php echo $row['CompanyName']; ?></td>
<td><?php echo $row['Product']; ?></td>
<td><?php echo $row['ProductLine']; ?></td>
<td><?php echo $row['DealerClass']; ?></td>
<td><?php echo $row['RequestStatus']; ?></td>
<td style="text-align: center">
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn btn-danger" href="#delModal" data-toggle="modal"><i class="icon-trash icon-white"></i> Delete</a>
<a class="btn update" href="#editModal<?php echo$i?>" data-sfid='"<?php echo $row['SFID'];?>"' data-toggle="modal">Edit</a>
<!--Yor Edit Modal Goes Here-->
<div id="editModal<?php echo $i; ?>" class="modal hide fade in" role="dialog" ria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Edit Customer Details</h3>
</div>
<div>
<form class="contact">
<fieldset>
<div class="modal-body">
<?php echo $row['SFID']; ?>
<ul class="nav nav-list">
<li class="nav-header">SFID</li>
<li><input class="input-xlarge" type="text" name="mysfid" id="mysfid"></li>
<!--<li class="nav-header">Company</li>
<li><input class="input-xlarge" value=" " type="text" name="mycompany"></li>
<li class="nav-header">Dealer Class</li>
<li><input class="input-xlarge" value=" " type="text" name="mydealerclass"></li> -->
</ul>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-success" id="submit">Approved</button>
Close
</div>
</div>
</div>
</div>
</td>
</tr>
<?php $i++; } ?>
</table>
take $i = 1 above for loop and increament it in each iteration of for loop..so it will take each records
Your Form
<a class='btn update' href='#editModal<?php echo $i;?>' data-sfid='".$row['SFID']."' role='button' data-toggle='modal'>Edit</a>
Modal Window
<div id="editModal<?php echo $i;?>" class="modal hide fade in" style="display: none; ">
That's because you fill the edit modal with the $row data, which by then, is on the last item.
To get data for a specific row, you could create a javascript object/array and then fetch the data by making use of the data-rfid parameter in the "Edit" link. Or you can fetch the row with Ajax for example.

Categories