I have a table that I want to assign a staff member to for each row. I want a dropdown on the last column with all the staff members so I can assign a staff member by clicking their username in the dropdown.
I'm trying to do a while loop inside a while loop but am getting an error.
This is my current code:
<table class="table table-bordered table-striped js-dataTable-full table-header-bg">
<thead>
<tr>
<th>Actions</th>
<th>Username</th>
<th>Service</th>
<th>Price</th>
<th>Date Ordered</th>
<th>Account Email</th>
<th>Account Password</th>
<th>Status</th>
<th>Assign to staff</th>
</tr>
</thead>
<tbody>
<?php
$clients_result = mysqli_query($con, "SELECT * FROM boosting_orders ORDER BY id ASC");
$query = mysqli_query( $con, "SELECT * FROM users" );
if(mysqli_num_rows($clients_result) > 0) {
while($payment_row = mysqli_fetch_array($clients_result)) {
echo '
<tr id="no_enter">
<td style="text-align: center;">
<div class="btn-group">
<a class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="" data-original-title="Edit Order" href="orders_admin?action=edit&identification='.$payment_row['id'].'"><i class="fa fa-pencil"></i></a>
<a class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="" data-original-title="Remove Order" href="orders_admin?action=delete&identification='.$payment_row['id'].'"><i class="fa fa-times"></i></a>
</div>
</td>
<td>
'.$payment_row['users_name'].'
</td>
<td>
'.$payment_row['service'].'
</td>
<td>
$'.$payment_row['price'].'
</td>
<td>
'.$payment_row['date_ordered'].'
</td>
<td>
'.$payment_row['email'].'
</td>
<td>
'.$payment_row['password'].'
</td>
<td>
'.($payment_row['status'] == 'Completed' ? '<span class="label label-success" data-toggle="tooltip" title="" data-original-title="Your account has successfully been boosted">Completed</span>' : '<span class="label label-info" data-toggle="tooltip" title="" data-original-title="This order is either still pending or corrupt">Pending</span>').'
</td>
<td>
<select name="assign_staff" class="form-control">
'. while($row = mysqli_fetch_array($query)) { .'
<option value="'.$row['username'].'">'.$row['username'].'</option>
'. } .'
</select>
</td>
</tr>
';
} } else { } ?>
</tbody>
you can't concatenate string with while syntax,
the code in the last <td> should be:
echo '<select name="assign_staff" class="form-control">';
while ($row = mysqli_fetch_array($query)) {
echo '<option value="' . $row['username'] . '">' . $row['username'] . '</option>';
}
echo '</select>
Related
I already create a delete button, but when I click it no showing any error message and the cart item and the item in database no get deleted.
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-sm btn-danger delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
This is the delete button function
if(isset($_POST['delete_cart_btn']))
{
$prod_id = mysqli_real_escape_string($con, $_POST['prod_id']);
$prod_query = "SELECT * FROM carts WHERE id='$prod_id' ";
$prod_query_run = mysqli_query($con, $prod_query);
$prod_data = mysqli_fetch_array($prod_query_run);
$image = $prod_data['image'];
$delete_query = "DELETE FROM carts WHERE id='$prod_id' ";
$delete_query_run = mysqli_query($con, $delete_query);
if($delete_query_run)
{
if(file_exists("../assets/images/products/".$image))
{
unlink("../assets/images/products/".$image);
}
echo 200;
}
else
{
echo 404;
}
}
Here my database
enter image description here
Here the button cart script and the button function
enter image description here
enter image description here
Here the full code the cart
<div id="fullCart" class="row">
<div class="col-sm-12 col-md-12 col-md-offset-1">
<table class="table table-hover">
<thead colspan="4">
<tr>
<p class="text-center"><strong><span style="font-size: 25px;"><i class="fa fa-shopping-cart" style="font-size:25px;color:black"></i> My Cart</span></strong></p>
</tr>
</thead>
<hr>
<thead>
<tr>
<th class="text-center">Product</th>
<th class="text-center">Quantity</th>
<th class="text-center">Price</th>
<th class="text-center">Total</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$subTotal = 0;
$quantity = 0;
$tax = 10;
$items = getCartItems();
foreach ($items as $citem) {
$subTotal += $citem['prod_qty'] * $citem['selling_price'];
$quantity += $citem['prod_qty'];
?>
<tr id="item_<?= $citem['prod_id']; ?>">
<td class="col-sm-8 col-md-6">
<div class="media">
<img class="media-object" src="assets/images/products/<?= $citem['image']; ?>" style="width: 100px; height: 100px;">
<h4 class="media-heading" style="position:relative; left:110px; top:-100px;"><?= $citem['name']; ?></h4>
</div>
</td>
<td class="col-sm-1 col-md-1 text-center">
<strong><?= $citem['prod_qty']; ?></strong>
</td>
<td class="col-sm-1 col-md-1 text-center">
<strong><span style="font-size: 18px;">$</span><span id="price"><?= number_format( $citem['selling_price'], 2 ); ?></span>
</strong>
</td>
<td class="col-sm-1 col-md-1 text-center">
<strong><span style="font-size: 18px;">$</span><span id="totalPrice_<?= $citem['prod_id']; ?>"><?= number_format( $citem['prod_qty'] * $citem['selling_price'], 2 ); ?></span>
</strong>
</td>
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-sm btn-danger delete_cart_btn" name="delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
</tr>
<?php } ?>
<tr>
<td colspan="4" align="right">Subtotal</td>
<td class="text-right">
<strong><span style="font-size: 18px;">$</span>
<span id="subTotal"><?= number_format( $subTotal, 2 ); ?></span>
</strong>
</td>
</tr>
<tr>
<td colspan="4" align="right">Taxes</td>
<td class="text-right">
<strong><span style="font-size: 18px;">$</span>
<span id="taxes"><?= number_format( $tax * $quantity, 2 ); ?></span>
</strong>
</td>
</tr>
<tr>
<td colspan="4" align="right">Total</td>
<td class="text-right">
<strong><span style="font-size: 18px;">$</span>
<span id="finalPrice"><?= number_format( $subTotal+($tax * $quantity), 2 ); ?></span>
</strong>
</td>
</tr>
<tr>
<td colspan="4" align="right">
<a href="index.php" class="btn btn-default">
<span class="glyphicon glyphicon-shopping-cart"></span> Place Order
</a>
</td>
<td >
<a href="checkout.php" class="btn btn-success">
Order <span class="glyphicon glyphicon-play"></span>
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
It seems you don't have a form to submit
There is no action when there is no form
Add a form tag and change your button type to submit
you need to data pass by POST so i 've added a method="POST" attribute to my form
<form>
<td class="col-sm-1 col-md-1" action="file_name.php" method="POST">
<button type="submit" class="btn btn-sm btn-danger delete_cart_btn" name="delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
</form>
instead of file_name.php put your php script file name
You did not name the button, so it doesn't send the data in the form.
<td class="col-sm-1 col-md-1">
<button type="button" class="btn btn-sm btn-danger delete_cart_btn" name="delete_cart_btn" value="<?= $citem['prod_id']; ?>">Delete</button>
</td>
if(isset($_POST['delete_cart_btn']))
{
$prod_id = mysqli_real_escape_string($con, $_POST['delete_cart_btn']);
$prod_query = "SELECT * FROM carts WHERE id='$prod_id' ";
$prod_query_run = mysqli_query($con, $prod_query);
$prod_data = mysqli_fetch_array($prod_query_run);
$image = $prod_data['image'];
$delete_query = "DELETE FROM carts WHERE id='$prod_id' ";
$delete_query_run = mysqli_query($con, $delete_query);
if($delete_query_run)
{
if(file_exists("../assets/images/products/".$image))
{
unlink("../assets/images/products/".$image);
}
echo 200;
}
else
{
echo 404;
}
}
I'm trying to generate a table of all user accounts and then have buttons next to each user to either delete or change the account level of the user (admin or not admin). What would be the best way to go about this?
Here's my code:
<?php
$query = mysql_query("SELECT user_name,user_id,user_email,user_level
FROM users
ORDER BY user_name ASC");
echo '<table class="table table-hover">
<thead class="thead-default">
<tr>
<th>Username</th>
<th>User ID</th>
<th>Email</th>
<th>Level</th>
<th>Options</th>
</tr>
</thead>';
while($row = mysql_fetch_array($query)){
echo '<tbody>
<tr>
<td class="col-3">' .$row['user_name'].'</td>
<td class="col-3">' .$row['user_id'].'</td>
<td class="col-3">' .$row['user_email'].'</td>
<td class="col-3">' .$row['user_level'].'</td>
<td class="col-3"><a class="btn btn-success" href="#" data-toggle="tooltip" title="Edit"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn btn-success" href="#" data-toggle="tooltip" title="Promote"><span class="glyphicon glyphicon-arrow-up"></span></a>
<a class="btn btn-danger" href="#"><span class="glyphicon glyphicon-arrow-down" data-toggle="tooltip" title="Demote"></span></a>
<a class="btn btn-danger" href="delete.php" data-toggle="tooltip" title="Delete"><span class="glyphicon glyphicon-trash"></span></a>
</td>
</tr>
</tbody>';
}
echo '</table>'; ?>
Any help would be appreciated :)
Edit: The admin/standard user is set via user_level with 0 being standard user and 1 being admin
edit 2: Added code
<?php
include 'connect.php';
include 'header.php';
mysql_query("UPDATE users SET user_level='1' WHERE user_id='".$_GET['user_id']."'");
die("User promoted to admin.");
include 'footer.php';
?>
Getting no luck with it, will try to add if statements for feedback on if database row changes
This here is example of code, because your questions lack some details, so i am sharing my code.
<table>
<tr>
<th>User Email </th>
<th>Date & Time </th>
<th>Complain Number</th>
<th>Complain Type</th>
<th>Description</th>
<th>Status</th>
</tr>
<?php
$ccount =1;
$email= $_SESSION["email"];
$query = mysqli_query($con,"Select * from new_complain where new_email =
'$email'");
while($rows = $query->fetch_assoc())
{
?>
<tr>
<input type="hidden" name="<?php echo 'sstd' . $ccount ; ?>" value="<?php
echo $rows['complain_type']; ?>" placeholder="Student Name" />
<td><?php echo $_SESSION["email"]; ?></td>
<td><?php echo $rows['complain_date']; ?></td>
<td><?php echo $rows['new_id']; ?></td>
<td><?php echo $rows['complain_type']; ?></td>
<td><?php echo $rows['new_complain']; ?></td>
<td><?php echo $rows['comlain_status']; ?></td>
</tr>
<?php
$ccount++;
} ?>
</table>
Without full details, it would be something like this:
<a class="btn btn-success" href="promote.php?id='.$row['user_id'].'" data-toggle="tooltip" title="Promote"><span class="glyphicon glyphicon-arrow-up"></span></a>
<a class="btn btn-danger" href="demote.php?id='.$row['user_id'].'"><span class="glyphicon glyphicon-arrow-down" data-toggle="tooltip" title="Demote"></span></a>
Then you need a promote.php in the same directory as this file, which would look like this:
<?php
mysql_query("UPDATE users SET user_level='1' WHERE user_id='".$_GET['user_id']."'");
die("User promoted to admin user.");
And a demote.php like so:
<?php
mysql_query("UPDATE users SET user_level='0' WHERE user_id='".$_GET['user_id']."'");
die("User demoted to standard user.");
So currently I am trying to figure out how I would add a dropdown menu to the code I've posted below. I've searched the internet but could not find a way that worked for me, I'm very new to coding so this is kind of difficult for me others may find this easy.
<table class="table table-bordered table-striped">
<thead> <!-- add class="thead-inverse" for a dark header -->
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>Crime(s)</th>
<th>Active</th>
<th>EDIT</th>
</tr>
</thead>
<tfoot>
<tr>
</tr>
</div>
</th>
</tfoot>';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["id"].'</td>
<td class="username" data-id1="'.$row["id"].'" contenteditable>'.$row["name"].'</td>
<td class="crime" data-id2="'.$row["id"].'" contenteditable>'.$row["crime"].'</td>
<td class="activated" data-id2="'.$row["id"].'" contenteditable>'.$row["activated"].'</td>
<td><button type="button" name="delete_btn" data-id3="'.$row["id"].'" class="btn btn-xs btn-danger btn_delete">DELETE</button></td>
</tr>
';
}
$output .= '
<tr>
<td></td>
<td id="name" contenteditable></td>
<td id="crime" contenteditable></td>
<td id="activated" contenteditable></td>
<td><button type="button" name="btn_add" id="btn_add" class="btn btn-xs btn-success">ADD ACCOUNT</button></td>
</tr>
';
}
else
{
$output .= '<tr>
<td colspan="4">Data not Found</td>
</tr>';
}
$output .= '</table>
</div>';
echo $output;
?>
Since you mentioned that you'd like to add the dropdown to the activated section of your table and that it should contain Yes, No and Being Verified, you can update that table column to be
<td class="activated" data-id2="'.$row["id"].'" contenteditable>
<select name="activated" id="activated">
<option value="Yes" '.(($row["activated"] == "Yes") ? 'selected="selected"':"").'>Yes</option>
<option value="No" '.(($row["activated"] == "No") ? 'selected="selected"':"").'>No</option>
<option value="Being Verified" '.(($row["activated"] == "Being Verified") ? 'selected="selected"':"").'>Being Verified</option>
</select>
</td>
This would allow the value from the db $row["activated"] get automatically selected in the dropdown.
From Here I am doing like I fetch data from database and display in table format still it is working fine, after I click the division_edit() function I want pass the value (id),how can do this.
<table id="dataTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $sql=m ysql_query( "SELECT * FROM division WHERE status !='1'"); for($i=1;$row=m ysql_fetch_assoc($sql);$i++){ ?>
<tr role="row" class="odd">
<td>
<?php echo $i;?>
</td>
<td>
<?php echo $row[ 'division'];?>
</td>
<td><a class="btn btn-success btn-xs" href="state_edit.php?id=<?php echo base64_encode($row['id']);?>" onclick="division_edit()" id="division_edit"><i class="fa fa-pencil-square-o"></i> Edit</a>
<button class="btn btn-danger btn-xs" data-href="state_delete.php?id=<?php echo base64_encode($row['id']);?>"
data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash"></i> Delete</button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</tfoot>
</table>
May this help you:
<table id="dataTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $sql=m ysql_query( "SELECT * FROM division WHERE status !='1'"); for($i=1;$row=m ysql_fetch_assoc($sql);$i++){ ?>
<tr role="row" class="odd">
<td>
<?php echo $i;?>
</td>
<td>
<?php echo $row[ 'division'];?>
</td>
<td><a class="btn btn-success btn-xs" href="state_edit.php?id=<?php echo base64_encode($row['id']);?>" onclick="division_edit(<?php echo $row['id']; ?>)" id="division_edit"><i class="fa fa-pencil-square-o"></i> Edit</a>
<button class="btn btn-danger btn-xs" data-href="state_delete.php?id=<?php echo base64_encode($row['id']);?>"
data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash"></i> Delete</button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</tfoot>
</table>
Try this..
<a class="btn btn-success btn-xs" href="state_edit.php?id=<?php echo base64_encode($row['id']);?>" onclick="division_edit(<?php echo $row['id'] ?>)" id="division_edit"><i class="fa fa-pencil-square-o"></i> Edit</a>
I'm using SB Admin Bootstrap.
My table didn't functioning as it should be (should be user can search the data in table and data arranged well), but :
This is my php code:
<div class="box-content">
<?php
if ($result) {
?>
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th class="text-left">User ID</th>
<th class="text-left">Username</th>
<th class="text-left">Password</th>
<th class="text-left">Full Name</th>
<th class="text-left">Task</th>
</tr>
</thead>
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '
<tbody>
<tr>
<td class="center">' . $row['userid'] . '</td>
<td class="center">' . $row['username'] . '</td>
<td class="center">' . $row['password'] . '</td>
<td class="center">' . $row['fullname'] . '</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="halflings-icon white zoom-in"></i>
</a>
<a class="btn btn-info" href="#">
<i class="halflings-icon white edit"></i>
</a>
<a class="btn btn-danger" href="#">
<i class="halflings-icon white trash"></i>
</a>
</td>
</tr>
</tbody>';
}}
?>
</table>
</div>
Answer moved from comment
You are repeating <tbody> element, so script are just taking first occurrence of this tag and executing some functions, leaving every further <tbody> intact.
Move out of loop, it must be unique in table.