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; ?>
Related
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 ;)
so i have a while loop and i am fethcing the name and the description of them from my db
so when ever i click on one of the parts i want the modal to display the name of the item that i clicked on in the modal i hope this picture would describe it better
below is the code i have so far
at the moment when i click on the modal i get displayed the name of the item which is first on the list no matter where i click
while($row = mysqli_fetch_assoc($result))
{
$name= $row['name_of_product'];
$description = $row['description']
?>
<a href="#" data-toggle="modal" data-target="#mymodal">
<div class="col-sm-4">
<?php echo name; ?>
<?php echo description ; ?>
</div>
</a>
<div id="mymodal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p><?php echo $name; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php } ?>
You are not doing things the way you have to do. You are re-creating your mymodal for every iteration of your while loop which is not a better way to achieve what you want.
Follow these steps:
Create your mymodal outside of your while loop.
Pass the ID of current row to a javascript function and populate the data of that id using javascript.
I have set the things which needs to be done. Try the following code
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!--- display table header row-->
<table style="width:100%">
<tr>
<th>name</th>
<th>description</th>
<th>Action</th>
</tr>
<?php
while($row = mysqli_fetch_assoc($result))
{
$name= $row['name_of_product'];
$description = $row['description'];
$id = $row['id']; // I am assuming that your table has auto incremented primary key column by the name of id, if not then replace that by $row['your_id_column']
?>
<!--- desplay the data in a table row -->
<tr>
<td id="<?php echo "name_".$id; ?>"><?php echo $name; ?></td>
<td id="<?php echo "description_".$id; ?>"><?php echo $description ; ?></td>
<td><div href="#" data-toggle="modal" data-target="#mymodal" onClick="showModal(<?php echo $id ; ?>)">Edit</div></td>
</tr>
<?php } ?>
</table>
<!--- Your modal -->
<div id="mymodal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p id="name"></p> <!--- name will be shown here-->
<p id="description"></p><!--- description will be shown here-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
function showModal(id)
{
// setting the values of clicked item in the bootstrap Modal
$("#name").text($("#name_"+id).text());
$("#description").text($("#description_"+id).text());
}
</script>
Looks like you are not serializing the modals... If you wanted to do things that way your code should be something like;
<!-- language-all: lang-html -->
while($row = mysqli_fetch_assoc($result)) {
$procuct_id = $row['ID'];
$name = $row['name_of_product'];
$description = $row['description']
?>
<a href="#" data-toggle="modal" data-target="#mymodal_<?php echo $procuct_id;?>">
<div class="col-sm-4">
<?php echo name; ?>
<?php echo description ; ?>
</div>
</a>
<div id="mymodal_<?php echo $procuct_id;?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p><?php echo $name; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php }
<--
A Better way to do it would be to write a javascript function to show the generic modal window, then run an ajax call to load your info into the "modal-body" div. You would have to pass a unique id to the call in order to have your ajax script hit the db and get the info to display.
It's been almost 4 years but I'm writing for everyone; change data-target(id) as row id.
edited code:
while($row = mysqli_fetch_assoc($result))
{
$name= $row['name_of_product'];
$description = $row['description']
?>
<a href="#" data-toggle="modal" data-target="#<?php echo $row['id']; ?>">
<div class="col-sm-4">
<?php echo name; ?>
<?php echo description ; ?>
</div>
</a>
<div id="<?php echo $row['id']; ?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p><?php echo $name; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php } ?>
I have a view in my project(PHP codeigniter), where the user can confirm or remove a particular record from the table of data displayed. When the user chooses to confirm a record, a modal pop up box shows up reassuring the confirmation. Clicking on the Confirm button in this modal will call a controller method to update the DB table appropriately via a consequent model method call. The same applies to the remove functionality in the view. I have implemented and called all the respective methods but it doesn't seem to affect in any way.
Code in context
1.View
<body>
<div class="content" style="background-color: white">
<div class="container-fluid" style="overflow-y: auto">
<legend>Vacancies Applied</legend>
<div>
<form class="form-horizontal" id="viewVacancy">
<?php echo $this->session->flashdata('msgconfirmed');
echo $this->session->flashdata('msgremoved');?>
<table class="table" id="vacancyApplicationTable" >
<thead class="active">
<tr style="background-color: lightblue;color: white" >
<th class="hidden-lg hidden-lg">ID</th>
<th>Company</th>
<th>Job Title</th>
<th>Applied Date</th>
<th>Closing Date</th>
<th>Status</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody >
<?php
if(count($vacanciesApplied)>0) {
foreach ($vacanciesApplied as $row) { ?>
<tr>
<td class="hidden-lg hidden-lg"><a><?php echo $row->vid; ?></a></td>
<td><?php echo $row->onBehalfOf; ?></td>
<td><?php echo $row->jobTitle; ?></td>
<td><?php echo $row->appliedDate; ?></td>
<td><?php echo $row->closingDate; ?></td>
<?php
if ($row->status == "pending")
{
$status = "Pending";
?>
<td><?php echo $status ?></td>
<td></td>
<td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-danger" href="#deleteVacancyApplication">Remove</a></td>
<?php
}
else
{
$status = "Accepted"; ?>
<td class="blink_text"><?php echo $status ?></td>
<td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-info" href="#confirmVacancyStatus">Confirm</a></td>
<td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-danger" href="#deleteVacancyApplication">Remove</a></td>
<?php
}
?>
</tr>
<?php }
}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
</body>
<script>
$(function () {
$('#vacancyApplicationTable').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth":true
});
});
</script>
<script>
$(document).on("click", ".open-AddBookDialog", function () {
var studentId = $(this).data('id');
var vid = $(this).data('name');
$(".modal-body #uid").val( studentId );
$(".modal-body #vid").val( vid );
});
</script>
<!-- Modal for confirmVacancyStatus -->
<div class="modal fade" id="confirmVacancyStatus" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false" data-backdrop="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color:lawngreen">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="uid"><i class="glyphicon glyphicon-check"></i> Confirm</h4>
</div>
<div class="modal-body">
<form method="post" id="formConfirm" action="<?php echo base_url() . 'index.php/studentDashboardController/confirmVacancy'?>">
<input type="text" name="vid" id="vid" value="" hidden/>
<div class="form-group">
<p>You got Accepted to follow this vacancy</p>
<p>Do you confirm this?</p>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success pull-right">Confirm</button>
</div>
</div>
</div>
</div>
<!-- Modal for deleteVacancyApplication -->
<div class="modal fade" id="deleteVacancyApplication" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false" data-backdrop="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color:red">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="uid"><i class="glyphicon glyphicon-remove"></i> Cancel</h4>
</div>
<div class="modal-body">
<form method="post" id="form" action="<?php echo base_url() . "index.php/studentDashboardController/deleteVacancyRequest"?>">
<input type="text" name="vid" id="vid" value="" hidden/>
<div class="form-group">
<p>Are you sure you want to cancel your application for this vacancy</p>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger pull-right">Cancel Application</button>
</div>
</div>
</div>
</div>
2.Controller- studentDashboardController/confirmVacancy
public function confirmVacancy()
{
if (isset($this->session->userdata['logged_in']))
{
$uid = ($this->session->userdata['logged_in']['userId']);
$data['notifyCount']= $this->notifications->getUnreadNotification($uid);
$data['title']= $this->notifications->getUnreadNotificationTitle($uid);
$data['notifyCount']= $this->notifications->getUnreadNotification($uid);
$data['users'] = $this->user->getUserNames();
$msg = $this->vacancyModel->confirmVacancyApplication($uid,$this->input->post());
$msgText = $msg['msg'];
$msgType = $msg['type'];
//Loading View
if($msgType == "danger")
{
$this->session->set_flashdata('msgconfirmed', '<div class="alert alert-danger text-center">'.$msgText.'</div>');
}
else
{
$this->session->set_flashdata('msgconfirmed', '<div class="alert alert-success text-center">'.$msgText.'</div>');
}
redirect(base_url('index.php/studentDashboardController/displayVacanciesApplied'));
}
else
{
$this->load->view('login/loginView');
}
}
3.Model- vacancyModel->confirmVacancyApplication
public function confirmVacancyApplication($uid, $post)
{
$vid = $post['vid'];
$data = array(
'availability' => $vid+""
);
$this->db->where("uid", $uid);
$status = $this->db->update("studentprofile", $data);
if($status)
{
$msg = "You have successfully confirmed";
$type = "success";
$msgData = array(
'msg' => $msg,
'type' => $type
);
return $msgData;
}
else
{
$msg = "Sorry. This vacancy could not be confirmed";
$type = "danger";
$msgData = array(
'msg' => $msg,
'type' => $type
);
return $msgData;
}
}
Interfaces
Any suggestions in this regard will be highly appreciated.
You are closing the before submit button.
Put form after input type="submit" tag. It will work
<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?
I need a help here.
I have an application - it queries some data from MySQL and present it in table (index.php file). Every row is a single customer record.
What I want to do is, when I click on the row, it opens customer record (customer.php file).
I tried the following code - when I click on the row, modal with remote page(customer.php only flashes, and then customer.php is loaded normally. I dont know why... does any body have an idea?
<table class="table table-hover container table-responsive">
<caption>Vyhledaní zákazníci</caption>
<thead>
<tr>
<th>Jméno</th>
<th>Příjmení</th>
<th>Email</th>
<th>Telefon</th>
<th>Adresa</th>
<th>Město</th>
<th>Akce</th>
</tr>
</thead>
<tbody>
<?php
while ($results = mysql_fetch_array($customers)) { ?>
<tr class="clickableRow active" href="customer.php?customerId=<?php echo $results['id'], '&search=', Input::get('search'); ?>" data-toggle="modal" data-target="#customerModal">
<td><?php echo $results['first_name']; ?> </td>
<td><?php echo $results['last_name']; ?> </td>
<td><?php echo $results['email']; ?> </td>
<td><?php echo $results['telephone']; ?> </td>
<td><?php echo $results['street']; ?> </td>
<td><?php echo $results['city']; ?> </td>
<td>Seznam zakázek
Nová zakázka
</tr>
<?php
} ?>
</tbody>
</table>
And modal:
<!-- Modal -->
<div class="modal fade" id="customerModal" 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">Karta zákazníka</h4>
</div>
<div class="modal-body"><div class="te"></div></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->