I want the data in my table to be clickable and show in a modal.
then get the id of that data(from the table) and show the rest of the data in the database in that modal.
I tried following this but it doesn't work, I dunno why
<table class="table table-hover table-bordered results" style="color:white;">
<thead>
<tr>
<th>Contact #</th>
<th>Picture</th>
<th >Name / Surname</th>
<th >Address</th>
</tr>
<tr class="warning no-result">
<td colspan="4"><i class="fa fa-warning"></i> No result</td>
</tr>
</thead>
<tbody>
<?php
$sqlb = "select * from debtors ";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc()){
$id=$rowb['contact #'];
?>
<tr a class="dropdown-item" data-toggle="modal" data-target="#logoutModal" style="color:white;">
<td><?php echo $rowb['contact #']; ?></td>
<td><?php echo $rowb['lname']; ?></td>
<td><?php echo $rowb['fname']; ?></td>
<td><?php echo $rowb['address']; ?></td></a>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- Logout Modal-->
<span>
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"></h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
</div>
<div class="modal-body"><?php echo $rowb['lname']; ?>, <?php echo $rowb['fname']; ?><BR>
<?php echo $rowb['balance']; ?>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<a class="btn btn-info" href="admin_logout.php">Yes</a>
</div>
</div>
</div>
</div>
</span>
I want my table row to show modal when clicked, then show data relating to the clicked row from the database in that modal
First of all the modal is not in the loop so you can't access $rowb in modal and secondly this is not the right way because after putting the modal in the loop it will create so many (hundreds or thousands) modals which is not good performance wise.
The right way is, create a modal and assign a class to the button and put the numeric id in the id attribute and on the click of that button make an ajax call and get the data and show it in the modal.
In this way the single modal will show you the right data dynamically.
You can use instead the try catch for the tbody of your table.
try {
$pdo = new PDO('mysql:host=localhost:3306;dbname=databaseName;', 'username', 'password' );
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare(
"SELECT * from debtors "
);
$flag = $stmt->execute();
if ( !$flag ) {
$info = $stmt->errorInfo();
exit( $info[2] );
}
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
$num = $num +1;
#$tbody .='<tr>';
//$tbody .='<td>'.$row["id"].'</td>
$tbody .='<td>'.$num.'</td
<input type="hidden" id="id'.$row["id"].'" value="'.$row["id"].'"/>
<input type="hidden" id="contact #'.$row["contact #"].'" value="'.$row["id"].'"/>
<input type="hidden" id="lname'.$row["id"].'" value="'.$row["lname"].'"/>
<input type="hidden" id="fname'.$row["id"].'" value="'.$row["fname"].'"/>
<input type="hidden" id="address'.$row["id"].'" value="'.$row["address"].'" />
';
$tbody .='<td>'.$row["contact #"].'</td>';
$tbody .='<td>'.$row["lname"].'</td>';
$tbody .='<td>'.$row["fname"].'</td>';
$tbody .='<td>P'.$row["address"].'</td>';
$tbody .='<td><input type ="button" id = "btnshow" value = "show" data-id="'.$row["id"].'"></input></td></a>';
}
}
catch ( PDOException $e ) {
echo $e->getMessage();
$pdo = null;
}
just make sure data in database has a unique ID's.
for the script :
$(document).on('click','#btnshow',function(){
var id_show = $(this).data('id');
var contact= document.getElementById('contact #'+id_edit).value;
var lname= document.getElementById('lname'+id_edit).value;
var fname= document.getElementById('fname'+id_edit).value;
var address= document.getElementById('address'+id_edit).value;
$(".modal-heading").html('')
$(".modal-body").html(
'<div class = "container-fluid" style="width:89%;" >' +
'<input type="hidden" class="form-control" id="id_row" name="id_row" value="'+ id_edit +'"></input>'+ <input type="text" id="contact" name= "contact" readonly="readonly" class="form-control" value="'+contact #+'"></input>'+ <input type="text" id="lname" name= "lname" readonly="readonly" class="form-control" value="'+lname+'"></input>'+ <input type="text" id="fname" name= "fname" readonly="readonly" class="form-control" value="'+fname+'"></input>'+<input type="text" id="address" name= "address" readonly="readonly" class="form-control" value="'+address+'"></input>'+
'</form></div>'
)
})
your html :
<table id ="products">
<col width="130">
<col width="80">
<thead>
<th>ID</th>
<th>CONTACT</th>
<th>LNAME</th>
<th>FNAME</th>
<th>ADDRESS</th>
</thead>
<tbody>
<?php echo $tbody;?>
</tbody>
</table>
Related
i am currently working on a module where faculty can post attendance to the students by selecting a dropdown(select box) which is generated dynamically by the information given by the faculty.When faculty selects a particular year and section respected student list is retrived and displayed in a table.But the requirement is once the attendance is posted to a particular class/section on a particular it cannot be opened again by the faculty
I have tried using mysql_num_rows() function to check if any rows are already present in the db or not on that particular date.But its not working the way i wanted
here is my entire code of the module excluding db file
<form action="take.php" method="Post">
<br>
<table class="table table-bordered table-hover ">
<tr>
<th>S.no</th>
<th>Student Name</th>
<th>Roll Number</th>
<th>Present</th>
<th>Absent</th>
</tr>
<?php
if (isset($_POST['search']))
{
$stu="Student";
$yr=$_POST['year'];
$se=$_POST['section'];
$subdr=mysql_query("SELECT subject FROM schedule WHERE id='$cuid' AND day='$d' AND class='$yr' AND section='$se'");
$subj=mysql_fetch_assoc($subdr);
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid' AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
$display=mysql_query("select name,id from login where role='$stu' AND academic='$yr' AND section='$se'");
$sno=0;
$count=0;
while ($row=mysql_fetch_array($display)) {
$sno++;
?>
<tr>
<td><?php echo $sno ?></td>
<td>
<?php echo $row['name'] ?>
<input type="hidden" name="name[]" value="<?php echo $row['name'] ?>">
</td>
<td>
<?php echo $row['id'] ?>
<input type="hidden" name="id[]" value="<?php echo $row['id'] ?>">
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Present" required>
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Absent" required>
</td>
</tr>
<?php
$count++;
}
}
?>
<tr>
<td colspan=5>
<center><label><?php echo "Subject : ".$subj['subject']; ?></label></center>
</td>
</tr>
<input type="hidden" name="yr" value="<?php echo $_POST['year']; ?>">
<input type="hidden" name="set" value="<?php echo $_POST['section']; ?>">
<?php
} ?>
</table>
<center><input type="submit" name="submit" value="Submit" class="btn btn-primary" >
</center>
</div>
the expected output should display a message saying "Records posted" based on query like :
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid'
AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
#display the student list
}
Your assignment is:
$dis_date=date("Y-m-d H:i:s");
so $dis_date contains both a date and a time of day. The query will only match if the records in the table have the exact same time of day, not just the same date.
You should leave the time out of the variable:
$dis_date=date("Y-m-d");
If the datatype of the column in the table is DATETIME, you also need to filter out the time from that, with:
AND DATE(ondate)='$dis_date' And subject='$subj_d'"
You don't need to do this if the datatype is DATE.
my php function is not working when im add my text area in form. other all input or working. if im add remark(text area) in form edit function cant show text in that remark. other input is visible but i cant save it again
please help me to fined my error
Code before "html"
<?php
function renderForm($id, $vehicle_type, $duration, $amount,$remarks, $error)
{
?>
my HTML form
<form action="" method="post">
<div class="row">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div class="col-lg-4 col-xs-6" class="form-group">
<label>Vehicle Type <span style="color:red;font-size:8px;"><i class="fa fa-asterisk" aria-hidden="true"></i></span></label>
<select name="vehicle_type" class="form-control">
<option <?php echo ($vehicle_type=='Bicycle')?'selected':'' ?>>Bicycle</option>
<option <?php echo ($vehicle_type=='Bike')?'selected':'' ?>>Bike </option>
<option <?php echo ($vehicle_type=='Cars')?'selected':'' ?>>Cars </option>
<option <?php echo ($vehicle_type=='Truck')?'selected':'' ?>>Truck</option>
<option <?php echo ($vehicle_type=='Others')?'selected':'' ?>>Others</option>
</select>
</div>
<div class="col-lg-4 col-xs-6" class="form-group">
<label>Duration </label> <span style="color:red; font-size:8px; "><i class="fa fa-asterisk" aria-hidden="true"></i></span>
<input type="text" value="<?php echo $duration; ?>" name="duration" class="form-control" maxlength="20" placeholder="Eg: 4 Hrs">
</div>
<div class="col-lg-4 col-xs-6" class="form-group">
<label><i class="fa fa-inr" aria-hidden="true"></i> Amount</label> <span style="color:red;font-size:8px;"><i class="fa fa-asterisk" aria-hidden="true"></i></span>
<input type="number" name="amount" value="<?php echo $amount; ?>" class="form-control" placeholder="00">
</div>
</div>
<div class="row">
<div class="col-lg-4 col-xs-6" class="form-group">
<label>Remarks</label>
<textarea class="form-control" name="remarks" <?php echo htmlspecialchars($remarks); ?> rows="3" placeholder="Enter ..."></textarea>
</div>
<div id="butn" class="col-lg-3 col-xs-3">
<button class="myButton" type="submit" name="submit" value="Submit" class="btn btn-block btn-success btn-lg">SAVE</button>
</div>
</div>
</form>
Code after "html"
<?php
}
// connect to the database
include('connection.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$vehicle_type = mysql_real_escape_string(htmlspecialchars($_POST['vehicle_type']));
$duration = mysql_real_escape_string(htmlspecialchars($_POST['duration']));
$amount = mysql_real_escape_string(htmlspecialchars($_POST['amount']));
$remarks = mysql_real_escape_string(htmlspecialchars($_POST['remarks']));
if ($vehicle_type=='' || $duration=='' || $amount=='' || $remarks=='')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($id, $vehicle_type, $duration, $amount, $remarks, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE price_normal SET vehicle_type='$vehicle_type', duration='$duration', amount='$amount', remarks='$remarks', WHERE id='$id'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: pnormal.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM price_normal WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$vehicle_type = $row['vehicle_type'];
$duration = $row['duration'];
$amount = $row['amount'];
$remarks = $row['remarks'];
// show form
renderForm($id, $vehicle_type, $duration, $amount, $remarks,'');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
}
?>
Take a look at the actual HTML in your browser. You're rendering the "remarks" content as an attribute of the textarea element:
<textarea class="form-control" name="remarks" <?php echo htmlspecialchars($remarks); ?> rows="3" placeholder="Enter ..."></textarea>
It should be the content of that element:
<textarea class="form-control" name="remarks" rows="3" placeholder="Enter ..."><?php echo htmlspecialchars($remarks); ?></textarea>
i have one view selection table in my application..in that i display all the view selection details..but what i want to do is i want to display the view selection depending on the role name..i have role_id in my selection table..i get the role names in dropdown..
this is my Controller:
public function vendor_view_selection()
{
$data['rolename']=$this->SelectionModel->getrolename();
$data['view_selection'] = $this->SelectionModel->getselection();
$this->load->view('selection/vendor_view_selection',$data);
}
This is my Model:
function getselection()
{
$this->db->select('*');
$this->db->from('selection');
$this->db->join('role','role.role_id= selection.role_id');
$this->db->join('candidates_details','candidates_details.candidate_id=selection.candidate_id');
$query = $this->db->get();
return $query->result();
}
select box for role name:(depending on selected role name need to display selection details)
<div class="form-group">
<label>Choose RoleName</label>
<select class="form-control" multiple class="form-control" data-placeholder="Role name" name="role_id" >
<option value="0"></option>
<?php foreach($rolename as $rows) { ?>
<option value="<?php echo $rows->role_id?>"><?php echo ucfirst($rows->role_name)?></option>
<?php } ?>
</select>
</div>
view:(view_selection)table
<div class="box-body">
<table id="" class="table table-bordered table-hover">
<thead>
<tr>
<th>selection </th>
<th>comments</th>
<th>results</th>
<th>candidate</th>
<th>role</th>
</tr>
</thead>
<?php
foreach ($view_selection as $idata) {
?>
<tbody>
<tr id="domain<?php echo $idata->selection_id;?>">
<td><?php echo $idata->selection;?></td>
<td><?php echo $idata->comments;?></td>
<td><?php echo $idata->results;?></td>
<td><?php echo $idata->candidate_id;?></td>
<td><?php echo $idata->role_id;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
Please anyone help me how to do that..
Thanks in advance..
Send list id by $.ajax to the special function in controller.
Then
echo $this->load->view('view_selection',array(),true);//return string of view
exit();
i hope so worked for you,
like to submit the array via $_POST, it works only with one foreach, how can i combine two foreach-arrays without getting everything doubled?
i tried it with "keTitle" and and "keSoll", but only once at a time works..
html:
<div class="table-responsive">
<table class="table table-striped">
<thead>
<td>Kühlgerät</td>
<td>Soll</td>
<td>Ist</td>
</thead>
<tbody>
<?php
$todo_query = mysqli_query($db, "SELECT * FROM temp_ke WHERE ListID = '1'");
while($row2 = mysqli_fetch_object($todo_query))
{
?>
<tr>
<th scope="row">
<?php echo "$row2->keTitle"; ?>
<input name="Title[<? echo "$row2->keTitle";?>]" value="<? echo "$row2->keTitle";?>" type="hidden">
</th>
<td><?php echo "$row2->keSoll"; ?> °C<br>
<input name="SollWert[<? echo "$row2->keSoll";?>]" value="<? echo "$row2->keSoll";?>" type="hidden">
</td>
<td>
<input class="shortinput" name="IstWert[]" value="" type="text"> °C<br>
</td>
</tr>
<?php }} ?>
</tbody>
</table>
<div class="tablefooter">Ausgefüllt von: <input name="Mitarbeiter" value="" type="text"></div>
<br>
<input type="submit" class="btn btn-default" value="Temperaturen eintragen">
</form>
</div>
next page to $_POST to:
<?php
foreach ($_POST['Title'] as $keTitle) {
foreach ($_POST['SollWert'] as $keSoll) {
echo "$keSoll<br>";
echo "$keTitle<br><br>";
}
}
?>
form value
$_POST['Title'] = 'Mein Titel';
$_POST['SollWert'] = '123';
thats the array:
$ksTitle = $_POST['Title'];
$keSoll = $_POST['SollWert'];
echo "$keSoll<br/>";
echo "$keTitle<br/>";
or in foreach:
foreach( $_POST AS $value){
echo $value . "<br/>";
}
output:
Mein Titel
123
so i am working on a contact form in html and i linked it to a sendmail.php file, as i still in the early process i was testing if fields are empty echo something... nothing is appearing. Please check my code it's still in it's early stage i'm afraid i have missed something out:
HTML
<form action="sendmail.php" method="post" >
<table width="101" border="0">
<tr>
<th scope="col">Full Name:</th>
</tr>
<tr>
<th width="95" scope="col"><input type="text" name="name" id="to" placeholder="Full Name" /></th><!-- -->
</tr>
<tr>
<th scope="row">Telephone:</th>
</tr>
<tr>
<th scope="row"><input type="text" name="telephone" id="telephone"placeholder="Telephone" />
</tr>
<tr>
<th scope="row">Subject:</th>
</tr>
<tr>
<th scope="row"><input type="text" name="subject" id="subject" placeholder="Subject" /></th>
</tr>
<tr>
<th scope="row">Message:</th>
</tr>
<tr>
<th scope="row"><textarea name="body" id="body" cols="45" rows="5" placeholder="Message"></textarea></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><input type="submit" name="submit" id="submit" value="Submit" /></th>
</tr>
</table>
</form>
PHP
<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php/';
$errors = array();
//if values are null echo null values
//in my case i kept null on purpose to see if working
//getting nothing
if(isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body']))
{
echo 'Null values';
}
?>
Your line
if(isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body'])){....}
should be
if(!isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body'])){.....}
On submit input type text are never NULL.
EDIT:
require_once 'libs/phpmailer/PHPMailerAutoload.php/';
Try this?
require_once 'libs/phpmailer/PHPMailerAutoload.php';
You didn't ask to do something as far as I can see.
This might work (all in one file, no need to create a second file)
<?
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(strlen($_POST['name']) == 0)
{ $error_msg ="- Please, provide us with your name.<br>"; }
if(strlen($_POST['*****WHATEVER*****']) == 0)
{ $error_msg ="- Fill in your problem :D.<br>"; }
if(!empty($error_msg))
{
echo "<b>Your message can't be send due to the following reason:</b> <br><br>";
echo $error_msg;
echo "<br>Click on <a href='javascript:history.back(1)'>Go back</a> and provide us with your name.<br><br>";
}
else
{
$recipient = "WHO NEEDS TO RECEIVE???";
$subject = "Subject, can be filled in via input field if you like";
$header = "From: " . $_POST['email'] . "\n";
$mail_body = "Contact script was used on " . date("d-m-Y") . " at " . date("H:i") . "h.\n";
$mail_body .= "Text you like to read:\n";
$mail_body .= "Name: " . $_POST['name'] . "\n";
$mail_body .= "\n\n -- End of contact --";
mail($recipient, $subject, $mail_body, $header);
print "Your mail is sent and whatever you like to tell them ;)";
}
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" name="contact">
******Then add your tables and label them as you please.****