I have designed one page consisting of one modal window which is opening with tag.
I want to pass some parameters to modal window which i will be using to populate table data based on the parameter value.It is working with one parameter but not working with another parameter.
Following is the HTML to open modal window......
<table id="MyTable1" class="table table-sm table-striped table-lightfont paginated">
<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 ($_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");
}
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");
}
foreach ($groupdata as $groupdatalist) {
//$allids[]=$groupdatalist["gma_id"]; ?>
<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 style="display:none"><input type="text" name="allids[]" value="<//?php echo "{$groupdatalist['gma_id']}"?>"/></td>-->
<td>
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
<a href="#" class="btn btn-light btn-sm shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
</span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Here is the modal window HTML.....
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">Menu List</h6>
</div>
<div class="modal-body">
<div class="control-container" style="padding:10px;">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php //session_start();
if (!empty($_SESSION['$SaveMsg'])) { echo $_SESSION['$SaveMsg']; }
unset($_SESSION['$SaveMsg']);
?>
</label>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="grpid" id="grpid"
value="" readonly required maxlength="50" style="width:100%;display:none;" autofocus />
<input class="text-control" type="text" name="grpname" id="grpname"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="moduleid" id="moduleid"
value="" readonly required maxlength="50" style="width:100%;display:none" autofocus />
<input class="text-control" type="text" name="modulename" id="modulename"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<?php $gmaid= "<script>document.writeln(gmaid);</script>";
echo $gmaid;?>
<!--table starts here -->
<table id="MyTable2" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","MENUNAME"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>-->
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","ACCESS_FLAG"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","OPTIONS"); ?></th>-->
</tr>
</thead>
<tbody>
</table>
<!-- table ends here -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
<i class="fa fa-close"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","CANCEL"); ?>
</button>
<button type="submit" name="updmenuperm" formnovalidate class="btn btn-primary"> <!--onclick="DispMsg(<//?php echo "'".$_SESSION['AlertMsg']."'";?>)"-->
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
</div>
Above code is working perfectly but if i am using another value as parameter it is not opening the modal window at all.
for ex. if i am using $groupdatalist['gma_id'] which is integer value, it is not opening modal window.
Multiple issues here.
First a </div> is missing at the end.
Then you are defining $groupdatalist in a foreach, but trying to use it outside the loop:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
If you want one modal per <td> you have to move your modal into the foreach loop.
Finally, you call the modal using $groupdatalist['gma_id']
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
but the modal ID is define using a different variable : $groupdatalist['gma_grp_id']:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>"
Related
I have some edit modal and i want it to show the detail of DATA in bootsrap modal based on ID. Here is my index code:
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?> </h1>
<div class="row">
<div class="col-lg-6">
<?= form_error('menu', '<div class="alert alert-danger" role="alert">','</div>'); ?>
<?= $this->session->flashdata('message'); ?>
Tambah User
<table class="table table-hover">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Nama</th>
<th scope="col">Email</th>
<th scope="col">Password</th>
<th scope="col">Role</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach ($userRole as $u) : ?>
<tr>
<th scope="row"><?= $i ; ?></th>
<td><?= $u['name']; ?> </td>
<td><?= $u['email']; ?> </td>
<td><?= $u['password']; ?> </td>
<td><?= $u['role']; ?> </td>
<td>
<a href="" class="badge badge-success" data-toggle="modal"
data-target="#editRoleModal">edit</a>
<a href="<?= base_url('admin/deleteuser/') . $u['id'];?>"
class="badge badge-danger">delete</a>
</td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
And here is my modal :
<!-- Modal Edit-->
<div class="modal fade" id="editRoleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<?= form_open_multipart('admin/usermanagement'); ?>
<div class="modal-body">
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="name" name="name" value="<?= $user['name']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="email" class="form-control" id="email" name="email" value="<?= $user['email']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="password" name="password"
value="<?= $user['password']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<select name="menu_id" id="menu_id" class="form-control">
<option value="">Select Role</option>
<?php foreach ($user_role as $u) : ?>
<option value="<?= $u['id']; ?>"><?= $u['role']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
For now It shows the data based on ID, but when i try to click edit button of another data, it show the same detail of one ID only.
I hope that every i click every data button, it shows different detail based on id. I've check similar case already but no one of them that work on my code. I just know my code need some jquery, but i just new on it.
like saad said, place it inside the loop
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800"><?= $title; ?> </h1>
<div class="row">
<div class="col-lg-6">
<?= form_error('menu', '<div class="alert alert-danger" role="alert">','</div>'); ?>
<?= $this->session->flashdata('message'); ?>
Tambah User
<table class="table table-hover">
<thead>
<tr>
<th scope="col">No</th>
<th scope="col">Nama</th>
<th scope="col">Email</th>
<th scope="col">Password</th>
<th scope="col">Role</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach ($userRole as $u) : ?>
<tr>
<th scope="row"><?= $i ; ?></th>
<td><?= $u['name']; ?> </td>
<td><?= $u['email']; ?> </td>
<td><?= $u['password']; ?> </td>
<td><?= $u['role']; ?> </td>
<td>
<a href="" class="badge badge-success" data-toggle="modal"
data-target="#editRoleModal<?=$i?>">edit</a>
<a href="<?= base_url('admin/deleteuser/') . $u['id'];?>"
class="badge badge-danger">delete</a>
<!-- Modal Edit-->
<div class="modal fade" id="editRoleModal<?=$i?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<?= form_open_multipart('admin/usermanagement'); ?>
<div class="modal-body">
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="name" name="name" value="<?= $u['name']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="email" class="form-control" id="email" name="email" value="<?= $u['email']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<input type="text" class="form-control" id="password" name="password"
value="<?= $u['password']; ?>">
</div>
<div class="mb-3">
<!-- <label for="exampleInputPassword1" class="form-label">Password</label> -->
<select name="menu_id" id="menu_id" class="form-control">
<option value="">Select Role</option>
<?php foreach ($user_role as $u2) : ?>
<option value="<?= $u2['id']; ?>"><?= $u2['role']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
</td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
Basically my modal is inside my div, but i want it outside of it... the problem is i am making use of a foreach statement aswell so it needs to be inside the foreach statement but also outside of the content div.
Here's my code:
<div class="content">
<div class="block block-rounded block-fx-pop block-themed">
<div class="block-header bg-gd-sublime">
<h3 class="block-title">Manage subscription plans</h3>
</div>
<div class="block-content block-content-full">
<!-- DataTables init on table by adding .js-dataTable-full class, functionality is initialized in js/pages/be_tables_datatables.min.js which was auto compiled from _es6/pages/be_tables_datatables.js -->
<table class="table js-dataTable-full">
<tbody>
<tr>
<th style="font-size: 12px;">Subscription name</th>
<th class="text-center" style="font-size: 12px;">Color</th>
<th class="text-center" style="font-size: 12px;">Price</th>
<th class="text-center" style="font-size: 12px;">duration</th>
<th class="text-center" style="font-size: 12px;">Account/day</th>
<th class="text-center" style="font-size: 12px;">Accounts type</th>
<th class="text-center" style="font-size: 12px;">Private</th>
<th class="text-center" style="font-size: 12px;">Users</th>
</tr>
<?php
$getPlans = $odb->query('SELECT * FROM plans ORDER BY price ASC');
foreach ($getPlans as $dPlans) {
if ($dPlans['private'] == 0) { $private = 'No'; } else { $private = 'Yes'; }
$id = $dPlans['ID'];
$getpeople = $odb->query("SELECT COUNT(*) AS total FROM `users` WHERE `membership` = '$id'");
$fetchpeople = $getpeople->fetch(PDO::FETCH_ASSOC);
$people = $fetchpeople['total'];
?>
<tr>
<td style="font-size: 12px;">
<a class="link-fx" href="#" data-toggle="modal" data-target="#exampleModalCenter<?php echo $id; ?>"><?=$dPlans['name']?></a>
</td>
<td class="text-center" style="font-size: 12px;"><i class="fa fa-circle" style='color:<?=$dPlans['color']?>'></i></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['price']?> €</td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['length']?> <?=$dPlans['unit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['limit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['accounts']?></td>
<td class="text-center" style="font-size: 12px;"><?=$private?></td>
<td class="text-center" style="font-size: 12px;"><?=$people?></td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Edit Plan: <?=$dPlans['name']?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post">
<div class="block-content">
<div class="row items-push">
<div class="col-lg-12">
<div class="form-group">
<label for="val-username">Name</label>
<input type="text" class="form-control" id="name2" name="name<?php echo $id; ?>" value="<?=$dPlans['name']?>">
</div>
<div class="form-group">
<label for="val-email">Price</label>
<input type="text" class="form-control" id="price2" name="price<?php echo $id; ?>" value="<?=$dPlans['price']?>">
</div>
<div class="form-group">
<label for="val-password">Duration</label>
<input type="text" class="form-control" id="length2" name="length<?php echo $id; ?>" value="<?=$dPlans['length']?>">
</div>
<div class="form-group">
<label for="val-skill">Time unit <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="unit<?php echo $id; ?>">
<option value="Days" <?php echo selectedUnit('Days',$dPlans['unit']); ?>>Days</option>
<option value="Weeks" <?php echo selectedUnit('Weeks',$dPlans['unit']); ?> >Week</option>
<option value="Months" <?php echo selectedUnit('Months',$dPlans['unit']); ?>>Month</option>
<option value="Years" <?php echo selectedUnit('Years',$dPlans['unit']); ?>>Year</option>
</select>
</div>
<div class="form-group">
<label for="val-password">Account per day</label>
<input type="text" class="form-control" id="length2" name="limit<?php echo $id; ?>" value="<?=$dPlans['limit']?>">
</div>
<div class="form-group">
<label for="val-password">Account type</label>
<input type="text" class="form-control" id="length2" name="accounts<?php echo $id; ?>" value="<?=$dPlans['accounts']?>">
</div>
<div class="form-group">
<label for="val-skill">Private <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="private<?php echo $id; ?>">
<option value="1" <?php echo selectedUnit(1,$dPlans['private']); ?>>Yes</option>
<option value="0" <?php echo selectedUnit(0,$dPlans['private']); ?>>No</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button name="update" value="<?php echo $id; ?>" class="btn btn-primary" type="submit">Update</button>
</div>
</div>
</div>
</div>
<?php }
?>
</tbody>
</table>
</div>
</div>
I've tried moving/adding divs but no change and it still displays like this:
I know my formating is really bad.
What Yasir Suggested me to do:
<div class="content">
<div class="block block-rounded block-fx-pop block-themed">
<div class="block-header bg-gd-sublime">
<h3 class="block-title">Manage subscription plans</h3>
</div>
<div class="block-content block-content-full">
<!-- DataTables init on table by adding .js-dataTable-full class, functionality is initialized in js/pages/be_tables_datatables.min.js which was auto compiled from _es6/pages/be_tables_datatables.js -->
<table class="table js-dataTable-full">
<tbody>
<tr>
<th style="font-size: 12px;">Subscription name</th>
<th class="text-center" style="font-size: 12px;">Price</th>
<th class="text-center" style="font-size: 12px;">Duration</th>
<th class="text-center" style="font-size: 12px;">Account/day</th>
<th class="text-center" style="font-size: 12px;">Accounts type</th>
<th class="text-center" style="font-size: 12px;">Users</th>
</tr>
<?php
$getPlans = $odb->query('SELECT * FROM plans ORDER BY price ASC');
foreach ($getPlans as $dPlans) {
if ($dPlans['private'] == 0) { $private = 'No'; } else { $private = 'Yes'; }
$id = $dPlans['ID'];
$getpeople = $odb->query("SELECT COUNT(*) AS total FROM `users` WHERE `membership` = '$id'");
$fetchpeople = $getpeople->fetch(PDO::FETCH_ASSOC);
$people = $fetchpeople['total'];
?>
<tr>
<td style="font-size: 12px;">
<a class="link-fx" href="#" data-toggle="modal" data-target="#exampleModalCenter<?php echo $id; ?>"><?=$dPlans['name']?></a>
</td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['price']?> €</td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['length']?> <?=$dPlans['unit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['limit']?></td>
<td class="text-center" style="font-size: 12px;"><?=$dPlans['accounts']?></td>
<td class="text-center" style="font-size: 12px;"><?=$people?></td>
</tr>
<?php }
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
$getPlans = $odb->query('SELECT * FROM plans ORDER BY price ASC');
foreach ($getPlans as $dPlans) {
if ($dPlans['private'] == 0) { $private = 'No'; } else { $private = 'Yes'; }
$id = $dPlans['ID'];
$getpeople = $odb->query("SELECT COUNT(*) AS total FROM `users` WHERE `membership` = '$id'");
$fetchpeople = $getpeople->fetch(PDO::FETCH_ASSOC);
$people = $fetchpeople['total'];
?>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter<?php echo $id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Edit Plan: <?=$dPlans['name']?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post">
<div class="block-content">
<div class="row items-push">
<div class="col-lg-12">
<div class="form-group">
<label for="val-username">Name</label>
<input type="text" class="form-control" id="name2" name="name<?php echo $id; ?>" value="<?=$dPlans['name']?>">
</div>
<div class="form-group">
<label for="val-email">Price</label>
<input type="text" class="form-control" id="price2" name="price<?php echo $id; ?>" value="<?=$dPlans['price']?>">
</div>
<div class="form-group">
<label for="val-password">Duration</label>
<input type="text" class="form-control" id="length2" name="length<?php echo $id; ?>" value="<?=$dPlans['length']?>">
</div>
<div class="form-group">
<label for="val-skill">Time unit <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="unit<?php echo $id; ?>">
<option value="Days" <?php echo selectedUnit('Days',$dPlans['unit']); ?>>Days</option>
<option value="Weeks" <?php echo selectedUnit('Weeks',$dPlans['unit']); ?> >Week</option>
<option value="Months" <?php echo selectedUnit('Months',$dPlans['unit']); ?>>Month</option>
<option value="Years" <?php echo selectedUnit('Years',$dPlans['unit']); ?>>Year</option>
</select>
</div>
<div class="form-group">
<label for="val-password">Account per day</label>
<input type="text" class="form-control" id="length2" name="limit<?php echo $id; ?>" value="<?=$dPlans['limit']?>">
</div>
<div class="form-group">
<label for="val-password">Account type</label>
<input type="text" class="form-control" id="length2" name="accounts<?php echo $id; ?>" value="<?=$dPlans['accounts']?>">
</div>
<div class="form-group">
<label for="val-skill">Private <span class="text-danger">*</span></label>
<select class="form-control" id="val-skill" name="private<?php echo $id; ?>">
<option value="1" <?php echo selectedUnit(1,$dPlans['private']); ?>>Yes</option>
<option value="0" <?php echo selectedUnit(0,$dPlans['private']); ?>>No</option>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button name="update" value="<?php echo $id; ?>" class="btn btn-primary" type="submit">Update</button>
</div>
</div>
</div>
</div>
</div>
<?php }
?>
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
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?
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.