The date range picker won't work properly in my inventory report, but for the sales report it works properly.
E.g. From 2018-03-07 to 2018-03-08, the 2018-03-08 does not show in the report.
Picture of the report:
Here is my code
<head>
<script>
$(function() {
$( "#tabs" ).tabs();
$('a[rel*=facebox]').facebox();
$( ".datepicker" ).datepicker();
});
$(document).ready(function(){
// Write on keyup event of keyword input element
$("#searchme").keyup(function(){
// When value of the input is not blank
if( $(this).val() != "")
{
// Show only matching TR, hide rest of them
$("#searchTbl tbody>tr").hide();
$("#searchTbl td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
// When there is no input or clean again, show everything back
$("#searchTbl tbody>tr").show();
}
});
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
</script>
<script>
function goBack() {
window.history.back();
}
</script>
<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<style>
.logo1 {
position: absolute;
right: 45%;
font-family: ""Lucida Console", Monaco, monospace";
top: 0%;
width: 80%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
h3{
font-size:20px;
font-family: "Arial";
}
table {
width:60%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: center;
}
#media print {
#page { margin: 0; }
body { margin: 1cm; }
#printPageButton {
display: none;
}
#e{
display:none;
}
.footer {
position: fixed;
left: 0;
font-family: ""Lucida Console", Monaco, monospace";
bottom: 0;
width: 100%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
}
</style>
<?php
if(isset($_POST['salesbtn'])) {
$from=$_POST['dayfrom'];
$to=$_POST['dayto'];
?>
</head>
<body>
<div style="height:50px;"></div>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-0">
<br><img src="../upload/logo.jpg" class="logo1" style="height:50px; width:50px;" ><br>
<center><h1>Inventory Report</h1><h3> From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>
<br>
<button id="printPageButton" class="btn btn-primary" onClick="window.print();">Print</button>
<button id="e" class="btn btn-primary" onclick="goBack()">Back</button>
<br><br>
<table width="100%" cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
<tr>
<th width="25%"><div align="center"><strong> Date </strong></div></th>
<th width="20%"><div align="center"><strong> User</strong></div></th>
<th width="20%"><div align="center"><strong>Action</strong></div></th>
<th width="20%"><div align="center"><strong>Product Name</strong></div></th>
<th width="20%"><div align="center"><strong>Quantity </strong></div></th>
</tr>
<?php
$iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid where inventory_date BETWEEN CAST('$from' AS DATE) AND CAST('$to' AS DATE) order by inventory_date desc ");
while($iqrow=mysqli_fetch_array($iq)){
?>
<tr>
<td class="hidden"></td>
<td><?php echo date('M d, Y h:i A',strtotime($iqrow['inventory_date'])); ?></td>
<td>
<?php
$u=mysqli_query($conn,"select * from `user` left join customer on customer.userid=user.userid left join supplier on supplier.userid=user.userid where user.userid='".$iqrow['userid']."'");
$urow=mysqli_fetch_array($u);
if($urow['access']==1){
echo "Admin";
}
elseif($urow['access']==2){
echo $urow['customer_name'];
}
else{
echo $urow['company_name'];
}
?>
</td>
<td align="right"><?php echo $iqrow['action']; ?></td>
<td align="right"><?php echo $iqrow['product_name']; ?></td>
<td align="right"><?php echo $iqrow['quantity']; ?></td>
</tr>
<?php
} }
?>
</tr> </td>
</table>
</div>
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>
EDITED:
This is my inventory.php
In here the user can input the range date from , to .
I dont know if this will help you guys.
I just want to know why it does not work well.
The problem is when i input 2018-03-08 - 2018-03-08 , the march 7 shows up but the march 8 wont show up.
<form action="total_inventory.php" method="post">
From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
<input type="submit" value="Show Report" name="salesbtn" ></form>
EDITED:
Here is my inventory table
INVENTORY DATA TABLE
UPDATED:
This is the output , still does not show the transaction from march 7
Sample Updated
There is time also in your table so you have to search with time. means your from should be d-m-Y 00:00:01 and your to should be d-m-Y 23:59:59
Updated : concat your date variables like this.
// Assume `$_POST['dayfrom'] = 03/15/2018;`
// Assume `$_POST['dayto'] = 03/31/2018;`
$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
echo $from; // if date is `03/15/2018` output like `2018-03-15 00:00:01`
echo $to; // if date is `03/31/2018` output like `2018-03-31 23:59:59`
// NOTE: check your date format is like this or not, then run the SQL query.
Updated Query:
$iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid where ( inventory_date BETWEEN CAST('$from' AS DATE) AND CAST('$to' AS DATE) ) order by inventory_date desc ");
Related
I have problem in my task where I suppose to display my record in horizontally with 3 columns
Unfortunately, my display is become vertical.
The task require us to use modulus (%) operator in order to display the records. The records are stored in database (id, title, picture, category, author). There are 11 books that store in database. Here is my PHP code:
<?php
include_once('config.php');
$result = mysqli_query($mysqli, "SELECT * FROM books ORDER BY id ASC");
?>
<style>
img {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
width: 200px;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding-left: 10px;
}
.p3 {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
padding-left: 10px;
color: blue;
}
</style>
<div class="container">
<center>
<h1>Koleksi Buku Peribadi</h1>
<table>
<?php
$x=11;
$y=3;
$i=$x % $y;
while($i && $book = mysqli_fetch_array($result)) {
?>
<tr>
<td>
<img src="Gambar-buku/<?php echo $book['picture'];?>">
<p class='p2'>Penulis:<span class='p3'> <?php echo $book['author'];?> </span>
<br> <i><?php echo $book['category'];?></i>
</p>
<center><button type="button">Details</button> </center>
</td>
</tr>
<?php
$i++; }
?>
</table>
</center>
</div>
Modulus is useful when you need to equally divide items into several categories.
Formally: index_of_category = index_of_item % number_of_categories
Practically: In your case, you have 3 categories (columns). For item with index i, you find index of its column with i % 3.
For making table layout work, you then need to:
print tr opening tag for every item belonging in column with index 0
print tr closing tag for every item belonging in column with index 2.
In my example, you can change number of columns easily by modifying $numberOfColumns variable.
<div class="container">
<center>
<h1>Koleksi Buku Peribadi</h1>
<table>
<?php
$numberOfColumns = 3;
for ($i = 0; (($book = mysqli_fetch_array($result)) !== null); $i++) {
$printRowOpeningTag = $i % $numberOfColumns === 0;
$printRowClosingTag = $i % $numberOfColumns === $numberOfColumns - 1;
if ($printRowOpeningTag) {?>
<tr>
<?php } ?>
<td><img src="Gambar-buku/<?php echo $book['picture'];?>">
<p class='p2'>Penulis:<span class='p3'> <?php echo $book['author'];?> </span>
<br> <i><?php echo $book['category'];?> </i>
</p>
<center><button type="button">Details</button> </center>
</td>
<?php if ($printRowClosingTag) { ?>
</tr>
<?php } ?>
<?php
} ?>
</table>
</center>
</div>
I dont know whats wrong with the code , when i search from march 3 - march 12 , the march 12 transaction does not show.
Thank you very much , this would help me a lot.
What I want is to show the march 12 transaction , like the e.g. given below .
I want it to show transactions from this date , to the date chosen.
E.G.
This is where I input it
Picture 1
March 3-12 Sample
Picture 2
March 3-13 Sample
Picture 3
This is my code
<head>
<script>
$(function() {
$( "#tabs" ).tabs();
$('a[rel*=facebox]').facebox();
$( ".datepicker" ).datepicker();
});
$(document).ready(function(){
// Write on keyup event of keyword input element
$("#searchme").keyup(function(){
// When value of the input is not blank
if( $(this).val() != "")
{
// Show only matching TR, hide rest of them
$("#searchTbl tbody>tr").hide();
$("#searchTbl td:contains-ci('" + $(this).val() + "')").parent("tr").show();
}
else
{
// When there is no input or clean again, show everything back
$("#searchTbl tbody>tr").show();
}
});
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"],
{
"contains-ci": function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
</script>
<script>
function goBack() {
window.history.back();
}
</script>
<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<style>
.logo1 {
position: absolute;
right: 45%;
font-family: ""Lucida Console", Monaco, monospace";
top: 0%;
width: 80%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
h3{
font-size:20px;
font-family: "Arial";
}
table {
width:60%;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: center;
}
#media print {
#page { margin: 0; }
body { margin: 1cm; }
#printPageButton {
display: none;
}
#e{
display:none;
}
.footer {
position: fixed;
left: 0;
font-family: ""Lucida Console", Monaco, monospace";
bottom: 0;
width: 100%;
background-color:#F8F8FF;
color: black;
text-align: center;
}
}
</style>
<?php
if(isset($_POST['salesbtn'])) {
$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
?>
</head>
<body>
<div style="height:50px;"></div>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-0">
<br><img src="../upload/logo.jpg" class="logo1" style="height:50px; width:50px;" ><br>
<center><h1>Inventory Report</h1><h3> From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>
<br>
<button id="printPageButton" class="btn btn-primary" onClick="window.print();">Print</button>
<button id="e" class="btn btn-primary" onclick="goBack()">Back</button>
<br><br>
<table width="100%" cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
<tr>
<th width="25%"><div align="center"><strong> Date </strong></div></th>
<th width="20%"><div align="center"><strong> User</strong></div></th>
<th width="20%"><div align="center"><strong>Action</strong></div></th>
<th width="20%"><div align="center"><strong>Product Name</strong></div></th>
<th width="20%"><div align="center"><strong>Quantity </strong></div></th>
</tr>
<?php
$iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid where inventory_date BETWEEN CAST('$from' AS DATE) AND CAST('$to' AS DATE) order by inventory_date desc ");
while($iqrow=mysqli_fetch_array($iq)){
?>
<tr>
<td class="hidden"></td>
<td><?php echo date('M d, Y h:i A',strtotime($iqrow['inventory_date'])); ?></td>
<td>
<?php
$u=mysqli_query($conn,"select * from `user` left join customer on customer.userid=user.userid left join supplier on supplier.userid=user.userid where user.userid='".$iqrow['userid']."'");
$urow=mysqli_fetch_array($u);
if($urow['access']==1){
echo "Admin";
}
elseif($urow['access']==2){
echo $urow['customer_name'];
}
else{
echo $urow['company_name'];
}
?>
</td>
<td align="right"><?php echo $iqrow['action']; ?></td>
<td align="right"><?php echo $iqrow['product_name']; ?></td>
<td align="right"><?php echo $iqrow['quantity']; ?></td>
</tr>
<?php
} }
?>
</tr> </td>
</br> </br>
<td style="color:red;" align="center"> Total:<?php
try {
require ("conn.php");
$stmt = $conn->prepare("SELECT SUM(sales_total) as 'test' FROM sales WHERE sales_date BETWEEN '$from' AND '$to'");
$stmt->execute();
$row=$stmt->fetch(PDO::FETCH_ASSOC);
echo $row['test'];
}
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
</table>
</div>
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>
The problem is occurring because you are casting your $to value as a DATE, which implies a TIME portion of 00:00:00. The BETWEEN then fails because '2018-03-12 11:31:25' is not <= '2018-03-12 00:00:00'
Changing the CAST of $to to a DATETIME should fix the problem. i.e.
$iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid where inventory_date BETWEEN CAST('$from' AS DATE) AND CAST('$to' AS DATETIME) order by inventory_date desc ");
I am trying to get the result from "headline" and "content" to show up one at a time and then fade in and out to the next result in a loop. Currently, it shows all the results at once and the fades in and out and then show all the results again. Any idea on how to get them to show one at a time TIA
<html>
<head>
<style>
#table1{/*table aspects and design */
border:1px solid #FFFFFF;
background:#FFFFFF;
display:none;
width: 60%;
margin-left: auto;
margin-right: auto;
}
th{/*align table headers*/
text-align:center;
}
td,th{
border:1px solid #FFFFFF;
text-align:center;
}
</style>
</head>
<table id="table1" cellpadding="5" cellspacing="1" width="50%">
<? if ($query=$pdo->prepare("SELECT * FROM `Announcements_Current`"))
{
/* select all information from the table and take it into the page */
$query->execute();
while ($result = $query->fetch(PDO::FETCH_ASSOC)){
$head = $result['headline'];/*puts result of headline from table into variable*/
$content = $result['content'];
/*puts result of content from table into variable*/
echo /* echo the table to display announcements*/'
<tr>
<th>
<h1>
'.$head.'
</h1>
</th>
</tr>
<tr>
<td>
<font size="4">
'.$content.'
</font>
</td>
</tr>';
}
}
?>
</table> <!--end of table-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
/* define script for jquery*/
for (var i = 0; i < 500; i++) {/* for loop to fade in and out the announcements*/
$(document).ready(function() {/*function to fade table in and out*/
$('#table1').fadeIn(2000);
$('#table1').delay(5000);
$('#table1').fadeOut(2000);
}
)};
</script>
You need to use a timer in your Javascript to show each row separately.
$(document).ready(function() {
var cur_row = 0;
setInterval(function() {
$("#table1 tr").fadeOut(2000).eq(cur_row).fadeIn(2000);
cur_row = (cur_row + 1) % $("table1 tr").length;
}, 5000);
});
I am working on event management site where i've to send emails and show the read, unread, bounced back...etc status email address in modal box. Showing the email addresses in modal box is working fine. I want to add datatables to it. When i Load the modal box first time it is showing the pagination but when i click on second time there is datatables error. Can Anyone help me in this please? Below is my code:-
$("body").on("click", ".textcontent", function(){
var option = $(this).attr("option");
var campaign_id = $("#campaign").val();
$.ajax({
type: "POST",
url: "get_emaillist.php",
data: { option : option, campaign_id : campaign_id },
success: function (resp){
$("#emailslist").html(resp);
$("#myModal").modal("show");
}
});
});
Below is the response from ajax
<?php
$option = $_REQUEST["option"];
$campaign_id = $_REQUEST["campaign_id"];
$emaillist = $gnrl->emaillist($campaign_id,$option);
$totalemail = count($emaillist);
?>
<div class="container">
<div class="row">
<div class="agent-profile">
<div class="col-lg-10 col-sm-10">
<div class="modal fade modelbx" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content" style="padding: 20px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo $option." Users List"; ?></h4>
<?php if($totalemail){ ?>
Export Users
<?php } ?>
</div>
<div class="modal-body">
<?php if(isset($campaign_id) && $campaign_id != "" && $campaign_id != "0"){ ?>
<div class="form-group">
<label class="control-label" for="selectbasic">Event Name</label><hr>
<div><span class="emaillist"><?php echo $campaigntitle = $dclass->select("tbl_campaign","campaignsubject","id = :id",array("id" => $campaign_id)); ?></span></div>
</div>
<?php } if($option == "Nominated" && $totalemail > 0){ ?>
<div class="form-group">
<table border="1" id="statstable">
<thead>
<tr>
<th>Nominated By User</th>
<th>Nominated User Name</th>
<th>Email</th>
<th>Company</th>
<th>Contact Number</th>
<th>Mobile Number</th>
</tr>
</thead>
<tbody>
<?php
if(isset($campaign_id) && $campaign_id != "0"){
$nominateduid = $dclass->select("tbl_nominateusers n left join tbl_user u on n.user_id = u.id","n.id,n.user_id,u.emailaddress"," AND n.campaign_id = '$campaign_id'");
}else{
$nominateduid = $dclass->select("tbl_nominateusers n left join tbl_user u on n.user_id = u.id","n.id,n.user_id,u.emailaddress");
}
foreach($nominateduid as $value){
$nominid = $value["id"];
if(isset($campaign_id) && $campaign_id != "0"){
$selcond = " AND campaign_id = '$campaign_id' AND id = '$nominid'";
}else{
$selcond = " AND user_id = '{$value["user_id"]}' AND id = '$nominid'";
}
$emaildet = $dclass->select("tbl_nominateusers","*",$selcond);
?>
<tr>
<td>
<?php
if($value["user_id"] == 0){
if(isset($campaign_id) && $campaign_id != "0"){
$nominatedemailaddress = $dclass->select("tbl_emailusers","useremail","campaign_id = :campaign_id AND user_id = :user_id",array("campaign_id" => $campaign_id, "user_id" => 0));
}else{
$nominatedemailaddress = $dclass->select("tbl_emailusers","useremail","user_id = :user_id",array("user_id" => 0));
}
}else{
$nominatedemailaddress = $value["emailaddress"];
}
echo $nominatedemailaddress;
?>
</td>
<td>
<?php
if(isset($emaildet[0]["nominatename"]) && $emaildet[0]["nominatename"] != ""){
echo $emaildet[0]["nominatename"];
}else{
echo "---";
}
?>
</td>
<td>
<?php
if($totalemail > 0){
echo $emaildet[0]["useremails"];
}else{
echo "There is No $option Email";
}
?>
</td>
<td>
<?php
if(isset($emaildet[0]["companyname"]) && $emaildet[0]["companyname"] != ""){
echo $emaildet[0]["companyname"];
}else{
echo "---";
}
?>
</td>
<td>
<?php
if(isset($emaildet[0]["contactnumber"]) && $emaildet[0]["contactnumber"] != ""){
echo $emaildet[0]["contactnumber"];
}else{
echo "---";
}
?>
</td>
<td>
<?php
if(isset($emaildet[0]["mobilenumber"]) && $emaildet[0]["mobilenumber"] != ""){
echo $emaildet[0]["mobilenumber"];
}else{
echo "---";
}
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php }else{ ?>
<div class="form-group">
<table border="1" id="statstable">
<thead><tr><th>Email Address</th></tr></thead>
<tbody>
<?php
if($totalemail > 0){
foreach($emaillist as $emails){
?>
<tr><td><?php echo $emails; ?></td></tr>
<?php } }else{ ?>
<tr><td><?php echo "There is No $option Email"; ?></td></tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="../css/bootstrap.min.css">
<link rel="stylesheet" href="../css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<style>
.modal.fade.in{ top: 10%!important; }
img{ max-width: 125%!important; }
.modal-dialog{ width: 900px!important; }
.modal .modal-body{ max-height: 420px; overflow-y: auto; }
.modal{ width: auto!important; }
.carttable, .carttable td{ padding: 5px; }
.modelbx{ background: rgba(0, 0, 0, 0) url("../images/login-main-bg.png") repeat scroll 0 0; bottom: 0; display: none; left: 0; position: fixed; right: 0; top: 0; z-index: 999999 !important; }
.sbbtn{ background-color: green; border: 0!important; border-radius: 10px; color: #fff; height: 35px; width: 90px; }
.alert-success{ color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6; }
.alert{ padding: 15px; margin-bottom: 20px; border: 1px solid transparent; border-radius: 4px; }
.textcontent{ float: left; width:100%; color: #5C9BD5; }
.emaillist{ color: #5698D4; line-height: 30px; margin: 10px; }
td, th{ padding: 10px!important; }
#statstable{ margin-bottom: 20px!important; }
</style>
<script type="text/javascript">
$(document).ready(function (){
$("#statstable").dataTable({
"aaSorting": [[0,"desc"]]
});
});
</script>
When you charge new elements with ajax, the javascript code doesn´t know those new elements. Maybe you can try recalling the data-tables init in the success section of the ajax call.
I have an editable grid where I want to edit the CSS such that the textarea to show the maximum width, but somehow I can't increase the width of the text area.
My database has three columns:
ID
Name
Gossip
I'm retrieving everything and displaying it in an editable grid using PHP.
index.php code
<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var textBefore = '';
$('#grid').find('td input').hover(function() {
textBefore = $(this).val();
$(this).focus();
}, function() {
var $field = $(this),
text = $field.val();
$(this).blur();
// Set back previous value if empty
if (text.length <= 0) {
$field.html(textBefore);
} else if (textBefore !== text) {
// Text has been changed make query
var value = {
'row': parseInt(getRowData($field)),
'column': parseInt($field.closest('tr').children().find(':input').index(this)),
'text': text
};
$.post('user.php', value)
.error(function() {
$('#message')
.html('Make sure you inserted correct data')
.fadeOut(3000)
.html(' ');
$field.val(textBefore);
})
.success(function() {
$field.val(text);
});
} else {
$field.val(text);
}
});
// Get the id number from row
function getRowData($td) {
return $td.closest('tr').prop('class').match(/\d+/)[0];
}
});
</script>
<title></title>
</head>
<body>
<?php if ($stmt): ?>
<div id="grid">
<p id="message">Click on the field to Edit Data</p>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gossip</th>
</tr>
</thead>
<tbody>
<?php while ($row = $stmt->fetch_assoc()): ?>
<tr class="<?php echo $row['Id']; ?>">
<td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No actors added yet</p>
<?php endif; ?>
</body>
</html>
user.php code
<?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$fields = array('row', 'column', 'text');
$sqlFields = array('Id', 'Name', 'Gossip');
foreach ($fields as $field) {
if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
sendError('No correct data');
exit();
}
}
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
sendError('Connect error');
exit();
}
$userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
$sqlFields[intval($_POST['column'])],
$db->real_escape_string($_POST['text']),
$db->real_escape_string(intval($_POST['row'])));
$stmt = $db->query($userQuery);
if (!$stmt) {
sendError('Update failed');
exit();
}
}
header('Location: index.php');
function sendError($message) {
header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
style.css code
body {
font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
border: 1px solid #d8d8bf;
}
th {
padding: 5px;
font: bold 14px Verdana, Arial, sans-serif;
}
td {
padding: 10px;
width: 200px;
}
td input {
margin: 0;
padding: 0;
// width:200px;
font: normal 14px sans-serif;
/** Less flicker when :focus adds the underline **/
border: 1px solid #fff;
}
td input:focus {
outline: 0;
border-bottom: 1px dashed #ddd !important;
}
#grid input {
// width: 200%;
}
You doing it wrong
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
Should be:
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
textarea is html tag name but not input type. so change this.
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
to
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
also add this css.
<style>
textarea {
resize: both;
width:700px;
}
</style>
also are you sure that you can get content using this.
<?php echo $row['Gossip']; ?>