Updating the status of Read messages [duplicate] - php

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 2 years ago.
i am trying to display and update read/unread messages. I have a column in database msg_read, that is by default has a value of 0. 0 means read, and 1 means unread. Need guidance to update the status when the message is read. With the guidance of Mr. Andre, the unread messages are showing Bold now, but when read, messages become normal (not bold).
<!-- Display User Messages Details Starts Here -->
<div class="tab-pane userprof-tab" id="tab-10">
<div class="table-responsive border-top">
<table class="table table-bordered table-hover mb-0 text-nowrap">
<thead>
<tr>
<th>Name</th>
<th>Jetski</th>
<th>Sender Email</th>
<th>Phone</th>
<th>Post Code</th>
<th>Message Date</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<?php
$SelectBoat = mysqli_query($con, "SELECT * FROM seller_contact WHERE seller_id='$user_id'");
while($row=mysqli_fetch_assoc($SelectBoat)){
$full_name = $row['full_name'];
$boatname = $row['boatname'];
$sender_email = $row['sender_email'];
$phone = $row['phone'];
$post_code = $row['post_code'];
$message = $row['message'];
$msg_date = $row['msg_date'];
$seller_id = $row['seller_id'];
$msg_read = $row['msg_read'];
?>
<?php
if(msg_read=="0"){
echo '<tr style="font-weight:900">
<td><?php echo $row['full_name'];?></td>
<td><?php echo $row['boat_name'];?></td>
<td><?php echo $row['sender_email'];?></td>
<td><?php echo $row['phone'];?></td>
<td><?php echo $row['post_code'];?></td>
<td><?php echo $row['msg_date'];?></td>
<td>
<!-- View Message -->
<i class="fa fa-eye"></i>
<!-- View Message -->
<!--****** View Message Modal ******-->
<div class="modal fade" id="view<?php echo $row['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><strong>From <?php echo $row['sender_email'];?></strong> </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p style="word-wrap: break-word; white-space: initial;"><?php echo $row['message'];?></p>
</div>
</div>
</div>
</div>
<!--****** End View Message Modal ******-->
</td>
</tr>'
} ?>else {
echo '<tr>
<td><?php echo $row['full_name'];?></td>
<td><?php echo $row['boat_name'];?></td>
<td><?php echo $row['sender_email'];?></td>
<td><?php echo $row['phone'];?></td>
<td><?php echo $row['post_code'];?></td>
<td><?php echo $row['msg_date'];?></td>
<td>
<!-- View Message -->
<i class="fa fa-eye"></i>
<!-- View Message -->
<!--****** View Message Modal ******-->
<div class="modal fade" id="view<?php echo $row['id'];?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><strong>From <?php echo $row['sender_email'];?></strong> </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p style="word-wrap: break-word; white-space: initial;"><?php echo $row['message'];?></p>
</div>
</div>
</div>
</div>
<!--****** End View Message Modal ******-->
</td>
</tr>'
} ?>
<?php } ?>
</tbody>
</table>
</div>
</div>

I found some errors in your code and some structural failures.
if you are working with PHP in a HTML page, use alternative syntax
see:
https://www.php.net/manual/en/control-structures.alternative-syntax.php
you don't need to rewrite the complete row again for the read message, only put a condicional on the style attribute.
you was calling read_msg instead of $read_msg
new code:
<div class="tab-pane userprof-tab" id="tab-10">
<div class="table-responsive border-top">
<table class="table table-bordered table-hover mb-0 text-nowrap">
<thead>
<tr>
<th>Name</th>
<th>Jetski</th>
<th>Sender Email</th>
<th>Phone</th>
<th>Post Code</th>
<th>Message Date</th>
<th>Message</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($SelectBoat)) : ?>
<?php
$full_name = $row['full_name'];
$boatname = $row['boatname'];
$sender_email = $row['sender_email'];
$phone = $row['phone'];
$post_code = $row['post_code'];
$message = $row['message'];
$msg_date = $row['msg_date'];
$seller_id = $row['seller_id'];
$msg_read = $row['msg_read'];
?>
<tr <?= ($msg_read == "0") ? 'style="font-weight:900"' : '' ?>>
<td><?php echo $row['full_name']; ?></td>
<td><?php echo $row['boat_name']; ?></td>
<td><?php echo $row['sender_email']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['post_code']; ?></td>
<td><?php echo $row['msg_date']; ?></td>
<td>
<!-- View Message -->
<i class="fa fa-eye"></i>
<!-- View Message -->
<!--****** View Message Modal ******-->
<div class="modal fade" id="view<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><strong>From <?php echo $row['sender_email']; ?></strong> </h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p style="word-wrap: break-word; white-space: initial;"><?php echo $row['message']; ?></p>
</div>
</div>
</div>
</div>
<!--****** End View Message Modal ******-->
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
UPDATE:
to update the status of the message just like i told you in the commnent. add this to your code:
add this sttribute to your view button:
onclick="readMSG(this, '<?php echo $row['id']; ?>')"
add this script and modify to work in your case:
<script>
function readMSG(attribute, id) {
$(attribute).parent().parent().css('font-weight', 'normal')
$.ajax({
type: "GET",
url: "readmsg.php",
data: {
id: id
},
success: function (){
$(attribute).parent().parent().css('font-weight', 'normal')
}
});
}
</script>
the php controller file readmsg.php:
$update = mysqli_query($con, "UPDATE `seller_contact` SET `read_msg`=1 WHERE `id` =" . $_GET['id']);
if ($update) {
return ['success' => 'success'];
} else {
return ['error' => 'error'];
}
try to understand the code and adapt to work in your case. if work, don't forgot to accept the answer ;)

Related

Edit multiple data in table for each different user php codeigniter 4

I have a table
I can add 1 question and the added question is spread to all user, but when edited, only 1 row is edited. So if i try to edit question 1 with question id 1 it should also edit the question 1 with id 2.
Is there anyway to solve this?
my table
<table id="tbl_data" class="table table-striped table-bordered zero-configuration">
<thead>
<tr>
<th>No</th>
<th>Question</th>
<th>Question ID</th>
<th>User ID</th>
<th><i class="ft-plus-circle"></i> Add</th>
</tr>
</thead>
<tbody>
<?php $numbering = 1;
foreach ($dataQuestion as $row) : ?>
<tr>
<td><?= $numbering++; ?></td>
<td><?= $row["question"]; ?></td>
<td><?= $row["id"]; ?></td>
<td><?= $row["id_user"]; ?></td>
<td>
<i class="ft-edit"></i>
<i class="ft-trash-2"></i>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
my modal edit
<?php foreach ($dataQuestion as $row) : ?>
<div class="modal fade" id="ModalEdit<?php echo $row['id']; ?>" arta-labelledby="ModalEditLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="ModalEditQuestionLabel">Edit Question</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="outline-style: none;">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="<?= base_url('/displayData/updateQuestion/' . $row["id"]) ?>" method="post">
<?= csrf_field(); ?>
<div class="form-group">
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Write..." name="question" required><?php echo $row['question']; ?></textarea>
</div>
<button type="submit" class="btn btn-primary btn-block" name="button">Save</button>
</form>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
my controller
public function updateQuestion($id)
{
$dataStored = new questionModel();
$questionModel= $this->questionModel->findAll();
$userModel= $this->userModel->findAll();
foreach ($userModel as $row) {
$data = [
'question' => $this->request->getPost('question')
];
$dataStored->updateData($data, $id);
}
session()->setFlashdata('message', 'Data updated!');
return redirect()->to(base_url('displayData'));
}

How do I print only a specific window

I'm have a page where I can view the purchase history of sales
When I click on view full details this is what I get
The problem is when I click print full details this is what I get, I only want to print the window that pops up when I click on view full details
How do I print only the View Full Details window part?
Here's my code:
<!-- History -->
<div class="modal fade" id="detail<?php echo $hrow['salesid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<center><h4 class="modal-title" id="myModalLabel">Purchase Full Details</h4></center>
</div>
<div class="modal-body">
<?php
$sales=mysqli_query($conn,"select * from sales where salesid='".$hrow['salesid']."'");
$srow=mysqli_fetch_array($sales);
?>
<div class="container-fluid">
<div class="row">x
<div class="col-lg-12">
<p class="pull-right">Date: <?php echo date("F d, Y", strtotime($srow['sales_date'])); ?></p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<label>
<button onclick="printsales()">Print Full details</button>
<script>
function printsales() {
window.print();
}
</script>
</label>
<table width="100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Purchase Qty</th>
<th>SubTotal</th>
</tr>
</thead>
<tbody>
<?php
$total=0;
$pd=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid where salesid='".$hrow['salesid']."'");
while($pdrow=mysqli_fetch_array($pd)){
?>
<tr>
<td><?php echo ucwords($pdrow['product_name']); ?></td>
<td align="right"><?php echo number_format($pdrow['product_price'],2); ?></td>
<td><?php echo $pdrow['sales_qty']; ?></td>
<td align="right">
<?php
$subtotal=$pdrow['product_price']*$pdrow['sales_qty'];
echo number_format($subtotal,2);
$total+=$subtotal;
?>
</td>
</tr>
<?php
}
?>
<tr>
<td align="right" colspan="3"><strong>Total</strong></td>
<td align="right"><strong><?php echo number_format($total,2); ?></strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
You just need to insert simple javascript code to print whole page. And by clicking on Click here to Print you can get print window.
<script type="text/javascript">
function PrintElem(elem,title)
{
Popup($(elem).html(),title);
}
function Popup(data,title)
{
var mywindow = window.open('', '_blank','width=1000,height=700');
mywindow.document.write('<html><head><title>'+title+'</title></head>');
mywindow.document.write('<body onload="window.print()">');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
return true;
}
</script>
Click here to Print
Add an ID to elements you want to hide, for example:
<div id="dontprint"> This will be hidden on print mode </div>
<div> This will be shown on print mode </div>
Then, using CSS hide those elements you don't want to print. Adding a code like this at the end of your code.
<style>
#media print {
div#dontprint{
display: none;
}
}
</style>

Data Fetch inside Bootstrap Modal window

<table class="table table-bordered">
<tr>
<th>Model Code</th>
<th>Size</th>
<th>Type</th>
<th>Price</th>
<th>Specs</th>
</tr>
<?php
while($row = $result->fetch_assoc()){
$f1=$row['model_code'];
$f2=$row['size'];
$f3=$row['type'];
$f4=$row['price'];
$f5=$row['specs'];
?>
<tr>
<td><?php echo $f1 ?></td>
<td><?php echo $f2 ?></td>
<td><?php echo $f3 ?></td>
<td><?php echo $f4 ?></td>
<td>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal">SPECS</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title text-center" id="myModalLabel"><?php echo $f1 ?></h4>
</div>
<div class="modal-body">
<div class="froala-view">
<?php echo $f5 ?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php
} //while ends here
?>
</table>
I am trying to fetch data from my database.other section is ok. But which is inside the modal of bootstrap is not able to fetch new data. It only fetching the first data of the table.
What should i do?

Modal Popup with dynamic IDs

Here is my code
$sql = "select * from billbook where stcode =? and sem =?";
$query = $mysqli->prepare($sql);
$query->bind_param('si',$stcode, $sem);
$query->execute();
$query->store_result();
$query->bind_result($billno,$billdate,$stcode,$sem,$amount);
$x = 1;
while($query->fetch())
{
?>
<tr>
<td align='center'><?php echo $x ?></td>
<td align='center' id="bno"><?php echo $billno ?></td>
<td align='center'><?php echo $billdate?></td>
<td align='right'><?php echo $amount?>.00</td>
</tr>
<?php
}
?>
My aim is to show the details of the Bill Number in a Modal Dialog Popup in Bootstrap, when the user click the "bno" ID (Second Column), after processing the details in an external PHP file.
Please Help.
<td align="center" id="bno"><?= $billno ?></td>
<?php
// generate a modal per bill
$modals[] = array(
'billno' => $billno,
'modal_id' => 'billno-'.$billno,
'title' => 'Bill No. '.$billno,
'message' => 'Modal body here',
'dismiss_button_text' => 'Close'
);
?>
...
<?php foreach ($modals as $modal) : ?>
<!-- Modal -->
<div class="modal fade" id="billno-<?= $modal['billno'] ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title"><?= $modal['title'] ?></h4>
</div>
<div class="modal-body">
<p><?= $modal['message'] ?></p>
</div>
<div class="modal-footer">
<div class="form-group">
<button type="button" class="btn btn-success form-control" data-dismiss="modal"><?= $modal['dismiss_button_text'] ?></button>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>

Bootstrap show info based on id in modal

I want to show more info about the file from the database using modal instead adding more columns to the table, and also instead of opening new page.
here is my code
<table id="file" class="table table-bordered table-striped table-hover">
<?php
$result = mysql_query("SELECT * FROM files")
?>
<thead>
<tr>
<th>ID <i class="fa fa-sort"></i></th>
<th>Name <i class="fa fa-sort"></i></th>
<th>Size <i class="fa fa-sort"></i></th>
<th>Delete </th>
</tr>
</thead>
<tbody>
<?php
while($row = mysql_fetch_array( $result )) {
?>
<tr class="record">
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name']; ?> </td>
<td><?php echo $row['size']; ?> </td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
</tr>
<?php
}
?>
</tbody>
</table>
Thanks in advance.
If there any other way place say it.
You can replace the following data-target and modal ID with PHP, if that is what you mean.
<!--This calls the modal by data-target ID -->
<a data-toggle="modal" data-target="#myModal">This link calls the modal</a>
<!--modal content-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<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" id="myModalLabel"></h4>
</div>
<div class="modal-body">
<!-- your content goes here -->
</div>
<div class="modal-footer">
<center><button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button></center>
</div>
</div>

Categories