I have a problem in the column referring to the column Actions of my listings table. The error is as follows.
Parse error: syntax error, unexpected token "<" in C:\xampp\htdocs\mangas\view\form_select_manga.php on line 42`
This error is caused by:
<a class="btn btn-info" title="Edit" href="edit_manga.php?id_manga=<?php echo $id_manga ?>" role="button"><i class="fa fa-edit"></i> Edit</a>
<a class="btn btn-danger" title="Delete" href="delete_manga.php?id_manga=<?php echo $id_manga ?>" role="button"><i class="fa fa-trash"></i> Delete</a>
Only the two action buttons have this problem, I have difficulties to adapt the table without causing an error.
<div class="container" style="margin-top: 40px;">
<h4 class="text-center">Manga list</h4>
<br>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Publisher</th>
<th>Volumes</th>
<th>Discont</th>
<th>Collection value</th>
<th>Registration date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
require_once "../model/MangaDAO.php";
$manga = new MangaDAO();
foreach ($manga->selectAllMangas() as $value){
echo '<tr>';
echo '<td title="'.$value['id_manga'].'">'.$value['id_manga'].'</td>';
echo '<td title="'.$value['title'].'">'.$value['title'].'</td>';
echo '<td title="'.$value['publisher'].'">'.$value['publisher'].'</td>';
echo '<td title="'.$value['volumes'].'">'.$value['volumes'].'</td>';
echo '<td title="R$'.$value['discont'].'">R$'.$value['discont'].'</td>';
echo '<td title="R$'.$value['value'].'">R$'.$value['value'].'</td>';
echo '<td title="'.date('d/m/Y H:i:s', strtotime($value['registration_date'])).'">'.
date('d/m/Y H:i:s', strtotime($value['registration_date'])).'</td>';
<a class="btn btn-info" title="Edit" href="edit_manga.php?id_manga=<?php echo $id_manga ?>" role="button"><i class="fa fa-edit"></i> Edit</a>
<a class="btn btn-danger" title="Delete" href="delete_manga.php?id_manga=<?php echo $id_manga ?>" role="button"><i class="fa fa-trash"></i> Delete</a>
echo '</tr>'; echo '</p>';
}
?>
</tbody>
</table>
</div>
<?php
require_once "../model/MangaDAO.php";
$manga = new MangaDAO();
foreach ($manga->readAllMangas() as $value){
echo '<tr>';
echo '<td title="'.$value['id_manga'].'">'.$value['id_manga'].'</td>';
echo '<td title="'.$value['title].'">'.$value['title'].'</td>';
echo '<td title="'.$value['publisher'].'">'.$value['publisher'].'</td>';
echo '<td title="'.$value['volumes'].'">'.$value['volumes'].'</td>';
echo '<td title="R$'.$value['discount'].'">R$'.$value['discount'].'</td>';
echo '<td title="R$'.$value['value'].'">R$'.$value['value'].'</td>';
echo '<td title="'.date('d/m/Y H:i:s', strtotime($value['registering_date'])).'">'.
date('d/m/Y H:i:s', strtotime($value['registering_date'])).'</td>';
echo '<td>';
echo '<a class="btn btn-info" title="Update '.$value['title'].'"'.'href="/mangas/view/form_update_manga.php?id_manga='.$value['id_manga'].'"role="button" ><i class="fa fa-edit"></i> Update</a>';
echo " ";
echo '<a class="btn btn-danger" title="Delete '.$value['title'].'"'.'href="/mangas/controller/delete_manga.php?id_manga='.$value['id_manga'].'"role="button"><i class="fa fa-trash"></i> Delete</a>';
echo '</td>';
echo '</tr>';
}
?>
Related
I'm creating a table using ajax and php but there's one problem, the table isn't showing in my div. I'm really new to ajax so I don't really fully understand it yet.
Here's my div:
<div class="body" id="live-data">
</div>
Here's the ajax code:
$(document).ready( function() {
function fetch_data() {
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data){
$('#live_data').html(data);
}
});
}
fetch_data();
});
And here's fetch.php:
<?php
include('../global/db.php');
$output = '';
$sql ="SELECT * FROM students WHERE status = '0' AND stud_grade = '$level_id' ORDER BY date_enrolled DESC";
$result = mysqli_query($db, $sql);
$output .= '
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th width="135" class="noExport">Action</th>
<th width="90">LRN</th>
<th width="20">Level</th>
<th>Name</th>
<th width="20">Gender</th>
<th width="60">Type</th>
<th width="105" style="font-size: 14px!important;">Date Enrolled</th>
</tr>
</thead>
<tbody>';
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)){
$output .= '
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
';
}
}
else {
$output .= '
<tr>
<td colspan="12">Data not Found</td>
</tr>';
}
$output .= '
</tbody>
</table>
</div>';
echo $output;
?>
It would great if anyone could help because I just don't know why it doesn't work
Edit:
I've changed the code so it returns the data in the console tab and here's what shows up:
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th width="135" class="noExport">Action</th>
<th width="90">LRN</th>
<th width="20">Level</th>
<th>Name</th>
<th width="20">Gender</th>
<th width="60">Type</th>
<th width="105" style="font-size: 14px!important;">Date Enrolled</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
</tbody>
</table>
</div>
So it clearly returns the correct data but it just doesn't show up in the live-data div
Maybe take a look in your html where is your div. Your div id says "live-data" and in the ajax code you mentioned to fetch data for div id "#live_data" instead of "#live-data".
Maybe changing them for same name can solve your problem. I would use for thr div id and in the ajax same id names like "#liveData".
Example (same code, just edited to the right IDs, compare with your original):
Your HTML div
<div class="body" id="liveData">
</div>
Your ajax code
$(document).ready( function() {
function fetch_data() {
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data){
$('#liveData').html(data);
}
});
}
fetch_data();
});
Just append the correct Id of the div tag in sucess function
I have one table and in this table, I have two button Update and Disable I want to hide those buttons
I trying like this
<table id="example1" class="table table-bordered table-striped table-sm" style=" overflow: auto; ">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<?php
$hide = 'OFF';
if($hide == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
</tr>
<?php foreach($dispatch as $dis){?>
<tr>
<td><?php echo $dis->disp_ch_no;?></td>
<td><?php echo date("d-m-Y", strtotime($dis->disp_ch_date));?></td>
<td><?php echo $dis->from_branch_name;?></td>
<td><a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a></td>
<td><a class="btn btn-danger btn-sm" onclick="delete_dispatch('<?php echo $dis->disp_id; ?>');" title="Click here to delete your Dispatch record"><i class="fa fa-trash" style="color: #fff;"> Disable </i> </a>
</td>
</tr>
<?php }?>
</table>
this is my table
How can I hide these buttons
Try this,
<?php
$thswitch = 'OFF';
if($thswitch == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
whenever you want to show just $thswitch = 'ON'; it
You have to check the if () for each row as we did in th. Like:
<table id="example1" class="table table-bordered table-striped table-sm" style="overflow: auto;">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<?php $hide = 'OFF';
if ($hide == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
</tr>
<?php foreach($dispatch as $dis) { ?>
<tr>
<td> <?php echo $dis->disp_ch_no;?> </td>
<td> <?php echo date("d-m-Y", strtotime($dis->disp_ch_date));?> </td>
<td> <?php echo $dis->from_branch_name;?> </td>
<?php if ($hide == 'ON') { ?>
<td>
<a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a>
</td>
<td>
<a class="btn btn-danger btn-sm" onclick="delete_dispatch('<?php echo $dis->disp_id; ?>');" title="Click here to delete your Dispatch record"><i class="fa fa-trash" style="color: #fff;"> Disable </i> </a>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
Or by using CSS you can hide this columns as:
Create a CSS class like:
.hidethisColumn { display: none !important; }
Use it in you table as:
<th class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">Update</th>
<th class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">Delete</th>
Similarly in rows inside foreach():
<td class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">
<a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a>
</td>
Hello i just new to coding but i don't know how to add span on my table on my echo every-time keep moving the table i need help how to do syntax on my code
here is my original code for my table
<td><span id="name<?php echo $row['id']; ?>"><?php echo $row['name']; ?></td>
<td><span id="email<?php echo $row['id']; ?>"><?php echo $row['email']; ?></td>
<td><span id="username<?php echo $row['id']; ?>"><?php echo $row['username']; ?></td>
<td><span id="level<?php echo $row['id']; ?>"><?php echo $row['password']; ?></td>
this my other table for my edit but everytime i press the button it does not display any value in my edit
<td>'.$row["name"].'</td>
<td>'.$row["username"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["level"].'</td>
<td><a style="cursor:pointer;" class="btn btn-info edit" data-id="'.$row['id'].'"><span class="glyphicon glyphicon-edit" aria-hidden="true" ></span></a> || <a style="cursor:pointer;" class="btn btn-danger delete" data-id="'.$row['id'].'"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
what im trying to get how do i put id on this echo output to direct it to my button showing the value of id return all the value on that id.
while($row = mysqli_fetch_array($result)) {
$output .= '
<tr>
<td>'.$row["name"].'</td> <-- how do i add <span>,put id on this rows
<td>'.$row["username"].'</td> or how to add id on this table
<td>'.$row["email"].'</td>
<td>'.$row["level"].'</td>
<td>
<a style="cursor:pointer;" class="btn btn-info edit" data-id="'.$row['id'].'"><span class="glyphicon glyphicon-edit" aria-hidden="true" ></span></a> || <a style="cursor:pointer;" class="btn btn-danger delete" data-id="'.$row['id'].'"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
</tr>';
}
echo $output;
}
Here's your $output with <span>s in them:
$output .= '
<tr>
<td><span id="name'.$row["id"].'">'.$row["name"].'</span></td>
<td><span id="username'.$row["id"].'">'.$row["username"].'</span></td>
<td><span id="email'.$row["id"].'">'.$row["email"].'</span></td>
<td><span id="level'.$row["id"].'">'.$row["level"].'</span></td>
<td>
<a style="cursor:pointer;" class="btn btn-info edit" data-id="'.$row['id'].'"><span class="glyphicon glyphicon-edit" aria-hidden="true" ></span></a> || <a style="cursor:pointer;" class="btn btn-danger delete" data-id="'.$row['id'].'"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
</td>
</tr>';
I have a user table where I have to display a delete button and I need to make sure the current user cannot delete themselves.
In order to do that, I wrote some code as shown below, but it doesn't work.
The user table appears with the delete button in all the users, but I need to make sure the current user cannot delete their own user account.
while($row = mysqli_fetch_array($result)) {
$output .='<tr>
<td>'.$row["user_id"].'</td>
<td>'.$row["fullname"].' </td>
<td>'.$row["user_role"].'</td>
<td>'.$row["username"].'</td>
<td>'.$row["password"].'</td>
<td>'.$row["branch_id"].'</td>
<td>'.$row["registered_date"].'</td>
<td>
<button id="'.$row["user_id"].'" class="btn btn-warning btn-xs edit_data"><i class="fa fa-edit "></i></button>
if('.$_SESSION['username'].'!='.$row["username"].') {
<a id="'.$row["user_id"].'" class="btn btn-danger btn-xs delete"><i class="fa fa-times"></i></a> } </td>
</tr>';
}
$output .= '</table>';
echo $output;
You can not execute PHP in a string, you need to split your string creation.
while ($row = mysqli_fetch_array($result)) {
$output .='<tr>
<td>'.$row["user_id"].'</td>
<td>'.$row["fullname"].' </td>
<td>'.$row["user_role"].'</td>
<td>'.$row["username"].'</td>
<td>'.$row["password"].'</td>
<td>'.$row["branch_id"].'</td>
<td>'.$row["registered_date"].'</td>
<td>
<button id="'.$row["user_id"].'" class="btn btn-warning btn-xs edit_data"><i class="fa fa-edit "></i></button>';
if ($_SESSION['username'] != $row["username"]) {
$output .= '<a id="'.$row["user_id"].'" class="btn btn-danger btn-xs delete"><i class="fa fa-times"></i></a>';
}
$output .= '</td></tr>';
}
$output .= '</table>';
echo $output;
Since you output your variable right after the loop - you can do the following
<table>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?=$row['user_id']; ?></td>
<td><?=$row['fullname']; ?></td>
<td><?=$row['user_role']; ?></td>
<td><?=$row['username']; ?></td>
<td><?=$row['password']; ?></td>
<td><?=$row['branch_id']; ?></td>
<td><?=$row['registered_date']; ?></td>
<td>
<?php
if($_SESSION['username'] != $row['username'])
{
?>
<a id="<?=$row['user_id']; ?>" class="btn btn-danger btn-xs delete"><i class="fa fa-times"></i></a>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</table>
I want to know how should we use div tags inside a table in PHP code. This is my code. Please tell me how to use it properly.
<tbody>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo "<tr>
<td>{$row['id']}</td>
<td><img width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
<td>{$row['item_name']}</td>
<td>{$row['description']}</td>
<td>{$row['quantity']}</td>
<td>echo '<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
<div class="c-input-group c-spinner">
<input type="text" class="form-control c-item-1" value="1">
<div class="c-input-group-btn-vertical">
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-down"></i>
</button>
</div>
</div>
</div>
</td>';
<td> <button>submit</button> </td>
</tr>";
}?>
</tbody>
I have tried using inverted comma's and braces but still, it shows error. What needs to be done here?
You can write the div inside table. Don't put all table inside php tag. remove html outside the <?php ?> php code. after that whenever you want to echo any value just used the php.
Customize your code like below,
<table>
<tbody>
<?php
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><img width='90px' height='90px' src='imageView.php?id=<?php echo $row["id"]; ?>' /> </td>
<td><?php echo $row['item_name']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td>
<div class="col-md-1 col-sm-3 col-xs-6 c-cart-qty">
<div class="c-input-group c-spinner">
<input type="text" class="form-control c-item-1" value="1">
<div class="c-input-group-btn-vertical">
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" type="button" data_input="c-item-1">
<i class="fa fa-caret-down"></i>
</button>
</div>
</div>
</div>
</td>
<td> <button>submit</button> </td>
</tr>
<?php } ?>
</tbody>
</table>
Within a double quote you can use a single quote
<tbody>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) {
echo "<tr>
<td>{$row['id']}</td>
<td><img width='90px' height='90px' src='imageView.php?id=".$row["id"]."' /> </td>
<td>{$row['item_name']}</td>
<td>{$row['description']}</td>
<td>{$row['quantity']}</td>
<td><div class='col-md-1 col-sm-3 col-xs-6 c-cart-qty'>
<div class='c-input-group c-spinner'>
<input type='text' class='form-control c-item-1' value='1'>
<div class='c-input-group-btn-vertical'>
<button class='btn btn-default' type='button' data_input='c-item-1'>
<i class='fa fa-caret-up'></i>
</button>
<button class='btn btn-default' type='button' data_input='c-item-1'>
<i class='fa fa-caret-down'></i>
</button>
</div>
</div>
</div>
</td>;
<td> <button>submit</button> </td>
</tr>";
}?>
</tbody>