hello
i get some help here yesterday for a problem i was having tablesorter. if i run the backend query on its own it displays the results ok. but i call it from another page from dropdown it displays all records and no errors are being seen in firebug. where am i going wrong? thanks
this code works on its own.
getuserlog.php
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$sql="SELECT * FROM logger_log WHERE idusr_log = '".$q."' order by datein_log desc";
$result = mysql_query($sql);
echo "<table id=\"userlog\" class=\"tablesorter\" cellspacing=\"1\">
<thead>
<tr>
<th align=\"left\">Ip Address</th>
<th align=\"left\">Date In</th>
<th align=\"left\">Date Out</th>
</tr>
</thead>";
echo "<tbody>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ip_log'] . "</td>";
echo "<td>" . date('d/m/Y H:i:s',strtotime($row['datein_log'])) . "</td>";
echo "<td>" . date('d/m/Y H:i:s',strtotime($row['dateout_log'])) . "</td>";
echo "</tr>";
}
echo"</tbody>";
echo "</table>";
mysql_close($con);
?>
<div id="pager" class="pager">
<form>
<img src="css/blue/first.png" class="first"/>
<img src="css/blue/prev.png" class="prev"/>
<input type="text" class="pagedisplay"/>
<img src="css/blue/next.png" class="next"/>
<img src="css/blue/last.png" class="last"/>
<select class="pagesize">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
</form>
</div>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<link href="css/blue/style.css" rel="stylesheet" type="text/css" />
<script>
$(function() {
$("#userlog")
.tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")});
});
</script>
and this is the page i am calling it from.
userlog.php
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuserlog.php?q="+str,true);
xmlhttp.send();
}
</script>
<div class="spacer"></div>
<div class="userlogTxt">This report shows all users who have logged in up until: <?php echo date("d/m/Y H:i:s"); ?></div>
<br />
<?php
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db("sample") or die(mysql_error());
$result2 = mysql_query('SELECT * FROM user_usr ORDER BY name_usr ASC', $conn);
echo '<select name="users" onchange="showUser(this.value)">';
echo '<option value="selected">'. 'Select a user' . '</option>';
while ($row = mysql_fetch_assoc($result2))
{
echo '<option value="'.$row['id_usr'].'">'.$row['name_usr'].'</option>';
}
echo '</select>';
?>
<br /><br />
<div id="txtHint" class="userlogTxt">Logging information will be shown here.</div></div>
#inti
it is not pulling any date from the db. just displaying header and pager.
userlog.php
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<link href="css/blue/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function showUser(str)
{
$.get("getuserlog.php?q="+str,function(response) {
$("#txtHint").html(response);
// Tablesorter will run, just after you loaded the ajax response
$("#userlog").tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")
});
});
}
</script>
<div class="spacer"></div>
<div class="userlogTxt">This report shows all users who have logged in up until: <?php echo date("d/m/Y H:i:s"); ?></div>
<br />
<?php
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db("sample") or die(mysql_error());
$result2 = mysql_query('SELECT * FROM user_usr ORDER BY name_usr ASC', $conn);
echo '<select name="users" onchange="showUser(this.value)">';
echo '<option value="selected">'. 'Select a user' . '</option>';
while ($row = mysql_fetch_assoc($result2))
{
echo '<option value="'.$row['id_usr'].'">'.$row['name_usr'].'</option>';
}
echo '</select>';
?>
<br /><br />
<div id="txtHint" class="userlogTxt">Logging information will be shown here.</div></div>
getuserlog.php
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$sql="SELECT * FROM logger_log WHERE idusr_log = '".$q."' order by datein_log desc";
$result = mysql_query($sql);
echo "<table id=\"userlog\" class=\"tablesorter\" cellspacing=\"1\">
<thead>
<tr>
<th align=\"left\">Ip Address</th>
<th align=\"left\">Date In</th>
<th align=\"left\">Date Out</th>
</tr>
</thead>";
echo "<tbody>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ip_log'] . "</td>";
echo "<td>" . date('d/m/Y H:i:s',strtotime($row['datein_log'])) . "</td>";
echo "<td>" . date('d/m/Y H:i:s',strtotime($row['dateout_log'])) . "</td>";
echo "</tr>";
}
echo"</tbody>";
echo "</table>";
mysql_close($con);
?>
<div id="pager" class="pager">
<form>
<img src="css/blue/first.png" class="first"/>
<img src="css/blue/prev.png" class="prev"/>
<input type="text" class="pagedisplay"/>
<img src="css/blue/next.png" class="next"/>
<img src="css/blue/last.png" class="last"/>
<select class="pagesize">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
</form>
</div>
where have i gone wrong? thanks
I recommend you, to use the jQuery Ajax functions in userlog.php, and since the script inside getuserlog.php is constant, move it to the userlog.php, something like this:
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<link href="css/blue/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function showUser(str)
{
$.get("getuserlog.php?q="+str,function(response) {
$("#txtHint").html(response);
// Tablesorter will run, just after you loaded the ajax response
$("#userlog").tablesorter({widthFixed: true, widgets: ['zebra']})
.tablesorterPager({container: $("#pager")});
});
}
</script>
EDIT: Put all you javascript in the main page. The ajax response should only contain the data you want to get from the server.
Related
Good Day!
I have a dropdown menu which select employee number and shows table data on basis of that particular selection. I have save as pdf code which saves table data in pdf. It is working fine but my table column headers are only shown not the values.
I have dropdown in one file having javascript which is sent to another file where my table is shown.
Below is the code for my all files and what I have tried for this so far.
For Dropdown:
<?php
include("connect-db.php");
?>
<html>
<head>
<title>PHP insertion</title>
<link rel="stylesheet" href="css/insert.css" />
<link rel="stylesheet" href="css/navcss.css" />
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","search_empnumber.php?emp_id="+str,true);
xmlhttp.send();
}
}
/*function showAssessories(acc) {
if (acc == "") {
document.getElementById("txtHint2").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint2").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","getassessories.php?emp_id="+acc,true);
xmlhttp.send();
}
}*/
</script>
</head>
<body>
<div class="maindiv">
<?php include("includes/head.php");?>
<?php include("menu.php");?>
<div class="form_div">
<form>
<div class="forscreen">
<h1>Search Records:</h1>
<p>You may search by Employee Number</p>
<select name="employeenumber" class="input" onchange="showUser(this.value)">
<option value="">Please Select Employee Number:</option>
</div>
<?php
$select_emp="SELECT distinct(emp_number) FROM employees";
$run_emp=mysql_query($select_emp);
while($row=mysql_fetch_array($run_emp)){
$emp_id=$row['emp_id'];
$first_name=$row['first_name'];
$last_name=$row['last_name'];
$emp_number=$row['emp_number'];
$total_printers=$row['total_printers'];
$total_scanners=$row['total_scanners'];
$total_pc=$row['total_pc'];
$total_phones=$row['total_phones'];
$other_equips=$row['other_equips'];
?>
<option value="<?php echo $emp_number;?>"><?php echo $emp_number;?></option>
<?php } ?>
</select>
<html>
</form>
</div>
<br>
<div id="txtHint"></div>
<br>
<div id="txtHint2"></div>
</div>
<?php include 'includes/foot.php';?>
</body>
</html>
The function for dropdown: onchange="showUser(this.value)"
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","search_empnumber.php?emp_id="+str,true);
xmlhttp.send();
}
}
search_empnumber.php File:
<!DOCTYPE html>
<html>
<form action="search_empnumber.php" method="POST">
<input type="submit" value="SAVE AS PDF" class="btnPDF" name="submit" />
</form>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
.link{ color:#00F; cursor:pointer;}
</style>
</head>
<body>
<?php
//$emp_id =($_REQUEST['emp_id']);
$emp_id =($_REQUEST['emp_id']);
$count=1;
include("connect-db.php");
//$sql = "SELECT * from employees where department='".$department."'";
//$sql = "select * from employees as pg inner join accessories as pd on pg.emp_number= pd.emp_number ";
//$result = mysql_query($sql) or die(mysql_error());
//$result = mysql_query($query) or die(mysql_error());
//$emp_id =($_POST['employeenumber']);
$sql="SELECT * FROM employees WHERE emp_number = '".$emp_id."'";
$result = mysql_query($sql) or die(mysql_error());
$count=1;
echo "<table>
<tr>
<th>S.No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Employee Number</th>
<th>Department</th>
<th>Email</th>
<th>Total Printers</th>
<th>Total Scanners</th>
<th>Total Pc</th>
<th>Total Phones</th>
<th>Other Equipments</th>
</tr>";
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $count . "</td>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['last_name'] . "</td>";
echo "<td>" . $row['emp_number'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['total_printers'] . "</td>";
echo "<td>" . $row['total_scanners'] . "</td>";
echo "<td>" . $row['total_pc'] . "</td>";
echo "<td>" . $row['total_phones'] . "</td>";
echo "<td>" . $row['other_equips'] . "</td>";
echo "</tr>";
$count++;
}
echo "</table>";
echo '<div class="forscreen">';
// echo '<br />';echo '<button class="btnPrint" type="submit" value="Submit" onclick="window.print()">Print</button>';
//echo '<input type="submit" value="SAVE AS PDF" class="btnPDFsearch" name="submit"/>';
// echo '<input type="submit" value="SAVE AS PDF" class="btnPDF" name="submit" />';
echo '</div>';
echo '<div class="forscreen">';
//echo '<br />';echo '<button class="btnPrevious" type="submit" value="Submit" onclick="history.back(); return false;">Previous Page</button>';
echo '</div>';
?>
</body>
</html>
PDF code (I tried) in same file of search_empnumber:
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include('connect-db.php');
?>
<?php
//if($_POST['submit']){
if (isset($_POST['submit'])){
require_once 'includes/practice.php';
$pdf->SetFont('times', '', 11);
$tb1 = '</br></br>
<table cellspacing="0" cellpadding="5" border="1">
<tr style="background-color:#f7f7f7;color:#333; ">
<td width="60">First Name</td>
<td width="60">Last Name</td>
<td width="80">Employee Number</td>
<td width="80">Department</td>
<td width="60">Email</td>
<td width="80">Total Printers</td>
<td width="80">Total Scanners</td>
<td width="60">Total PCs</td>
<td width="60">Total Phones</td>
<td width="60">Other Equipments</td>
</tr>
</table>';
include('connect-db.php');
//$emp_id =($_POST['emp_id']);
$emp_id =($_POST['employeenumber']);
$result1= mysql_query("SELECT * FROM employees where emp_number = '".$emp_id."'");
while($row = mysql_fetch_assoc($result1)){
$tb2 = '<table cellspacing="0" cellpadding="5" border="1">
<tr>
<td width="60">' . $row['first_name'] . '</td>
<td width="60">' . $row['last_name'] . '</td>
<td width="80">'. $row['emp_number'] .'</td>
<td width="80">'.$row['department'].'</td>
<td width="60">'.$row['email'].'</td>
<td width="80">'.$row['total_printers'].'</td>
<td width="80">'.$row['total_scanners'].'</td>
<td width="60">'.$row['total_pc'].'</td>
<td width="60">'.$row['total_phones'].'</td>
<td width="60">'.$row['other_equips'].'</td>
</tr>
</table>';
$tb1 = $tb1.$tb2;
}
$pdf->writeHTML($tb1, true, false, false, false, '');
ob_end_clean();
$pdf->Output('Report.pdf', 'D');
}
?>
The files i.e. practoce.php and pdf libraries are not added becuase they are just creating tables in defined formats
You are mixing up GET and POST. Try one (or both) of the following:
1) In the dropdown code, replace <form> with:
<form method="POST">
2) In the table generation code, read the value back with:
$emp_id =($_REQUEST['employeenumber']);
and also:
if (isset($_REQUEST['submit'])){
To add to your problems, in the first version of search_empnumber.php you posted, you read back $emp_id =($_REQUEST['emp_id']); when the posted value will actually be in $_REQUEST['employeenumber'].
I don't know which part is going wrong for you, but there's some strange things going on in that dropdown code:
<select name="employeenumber" class="input" onchange="showUser(this.value)">
<option value="">Please Select Employee Number:</option>
</div> <!-- ISSUE: Closed a div which was never opened. You're lucky the select box even shows anything-->
<?php
$select_emp="SELECT distinct(emp_number) FROM employees";
$run_emp=mysql_query($select_emp);
//ISSUE: You loop through a lot of data, but then do nothing with it. With every pass of the loop, you simply change the variables, and nothing else. I think you meant to move your <option> into the loop
while($row=mysql_fetch_array($run_emp)){
//ISSUE: You only selected 'emp_number' in your query. Most of these array keys are never filled
$emp_id=$row['emp_id'];
$first_name=$row['first_name'];
$last_name=$row['last_name'];
$emp_number=$row['emp_number']; //This is the only one filled
$total_printers=$row['total_printers'];
$total_scanners=$row['total_scanners'];
$total_pc=$row['total_pc'];
$total_phones=$row['total_phones'];
$other_equips=$row['other_equips'];
?>
<!--ISSUE: Only the last $emp_number from the query is filled. The rest you kept overwriting in your loop-->
<option value="<?php echo $emp_number;?>"><?php echo $emp_number;?></option>
<?php } ?>
</select>
i have a drop down list populated from a database(it is the first cell in a table row) then based on that selection i want it to populate the rest of the row from the same database, each cell is a different table in the database, so far i only have it populating the first cell (calories), i can't figure out how to get it to populate the rest of the cells, thanks
<?php
$link=mysqli_connect("localhost", "root", "");
mysqli_select_db($link,"meal_planner");
?>
<!DOCTYPE html>
<html>
<head>
<title>Meal Planner</title>
<link href="main2.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
// Hide all panels to start
var panels = $('.accordion > dd').hide();
// Show first panel on load (optional). Remove if you want
panels.first().show();
// On click of panel title
$('.accordion > dt > a').click(function() {
var $this = $(this);
// Slide up all other panels
panels.slideUp();
//Slide down target panel
$this.parent().next().slideDown();
return false;
});
});
</script>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<dl class="accordion">
<dt>Monday</dt>
<dd>
<table>
<tr>
<th>Breakfast</th>
<th>Calories</th>
<th>Protein</th>
<th>Carbs</th>
<th>Fat</th>
<th>Serving Sizing</th>
</tr>
<tr>
<td>
<select name="breakfa"s onchange="showUser(this.value)">
<option value="">Select a Protein:</option>
<?php
$res=mysqli_query($link,"select name, protein_id from protein");
while($row=mysqli_fetch_array($res))
{
?>
<option value="<?php echo $row["protein_id"]; ?>"><?php echo $row["name"]; ?></option>
<?php
}
?>
</select>
</td>
<td><div id="txtHint"><b>0</b></div></td>
<td>50</td>
<td>50</td>
<td>50</td>
<td><input type="" name=""></td>
</tr>
</table>
</dd>
<dt>Tuesday</dt>
<dd>TEST</dd>
<dt>Wednesday</dt>
<dd>TEST.</dd>
</dl>
</body>
</html>
php
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','meal_planner');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM protein WHERE protein_id = '".$q."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['calories'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I have a form in which a user select a reference of a candelabra.
When the choice done, a list of incidents relative to the candelabra appears in a bootstrap table.
The table is completed with items from a Mysql database.
All is ok. Now I'd like to add a button in another column called "test". But I have no buttons.. I put a screenshot of what I see..
My code is this one :
FORM FILE
<?php
require_once 'login.php';
$sql= "SELECT ptlum FROM ptlum where ptlum LIKE '%AZ%'";
$result = mysql_query($sql) or die("Requete pas comprise");
//while($data = mysql_fetch_array($result))
// {
//echo "<option>".$data[ptlum]."</option>";
// }
?>
<html>
<head>
<meta charset="utf-8">
<link href="examples.css" rel="stylesheet">
<link href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/lib/bootstrap.min.css" rel="stylesheet">
<link href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/lib/bootstrap-responsive.min.css" rel="stylesheet">
<link href="http://minikomi.github.io/Bootstrap-Form-Builder/assets/css/custom.css" rel="stylesheet">
<link href="bootstrap.table.css" rel="stylesheet">
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form class="form-horizontal" >
<legend>Rechercher une panne en cours ou archivée</legend>
<div class="control-group">
<label class="control-label" for="selectbasic-0">Sélectionner un point lumineux</label>
<div class="controls">
<select name="users" onchange="showUser(this.value)">
<?php
while ($row = mysql_fetch_array($result))
{
echo "<option>".$row[ptlum]."</option>";
}
?>
</select>
</div>
</div>
</form>
<script src= "jquery.js"></script>
<script src= "bootstrap.min.js"></script>
<script src= "bootstrap.table.js"></script>
<br>
<div id="txtHint"><b></b></div>
</body>
</html>
PHP FILE WITH CALLING THE DATABASE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet">
</head>
<body>
<script src= "jquery.js"></script>
<script src= "https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script src= "https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>
<?php
$q = $_GET['q'];
//echo $q;
$con = mysqli_connect('localhost','root','root','sdeer');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM depannages WHERE ptlum = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table id=\"example\" class=\"table table-striped table-bordered\" cellspacing=\"0\" width=\"100%\">
<tr>
<th>Pt Lum</th>
<th>Matériel</th>
<th>Prestation</th>
<th>Date</th>
<th>Nature</th>
<th>Test</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>" . $row['ptlum'] . "</td>";
echo "<td>" . $row['materiel'] . "</td>";
echo "<td>" . $row['presta'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['nature'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
echo "</table>";
mysqli_close($con);
?>
<script>
$(document).ready(function() {
var table = $('#example').DataTable( {
"columnDefs": [ {
"targets": -1,
"data": null,
"defaultContent": "<button>Click!</button>"
} ]
} );
</script>
</body>
</html>
How to make it if I want to have a button ? When the user will click on the button, a new window will appear.
Thanks !
You can make a anchor tag look like as button. Just you need to add role="button".
New Window Button
Edited Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet">
<script src= "jquery.js"></script>
<script src= "https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script src= "https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>
</head>
<body>
<?php
$q = $_GET['q'];
$con = mysqli_connect('localhost','root','root','sdeer');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM depannages WHERE ptlum = '$q'";
$result = mysqli_query($con,$sql);
?>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Pt Lum</th>
<th>Matériel</th>
<th>Prestation</th>
<th>Date</th>
<th>Nature</th>
<th>Test</th>
</tr>
</thead>
<tbody>
<?
while($row = mysqli_fetch_array($result))
{?>
<tr>
<td><?echo $row['ptlum'];?></td>
<td><?echo $row['materiel'];?></td>
<td><?echo $row['presta'];?></td>
<td><?echo row['date'];?></td>
<td><?echo $row['nature'];?></td>
<td>
New Window Button
</td>
</tr>
<?}?>
<tbody>
</table>
<?mysqli_close($con);?>
<script>
$(document).ready(function() {
var table = $('#example').DataTable( {
"columnDefs": [ {
"targets": -1,
"data": null,
"defaultContent": "<button>Click!</button>"
} ]
} );
</script>
</body>
</html>
i need to show different values only in drop down list.drop down list selection based result cal in ajax and display the related data show below in the drop down list.
How to pass the string value to ajax in this script.
Anyone pls guide me
<!doctype html>
<html class="no-js" lang="en">
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div class="row">
<div class="large-12 columns">
<h1></h1>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<!--Main Tab Start-->
<?php
$res=mysql_query("select DISTINCT tag,id from password");
if($res === false )
{
die(mysql_error());
}
?>
<form action="" method="post">
<select name="tagg" onchange="showUser(this.value)">
<option value="">Select Accounts</option>
<?php
while($row=mysql_fetch_array($res))
{
$dess=$row['tag'];
$id=$row['id'];
?>
<option value="<?php echo $id;?>"><?php echo $dess; ?></option>
<?php
}
?>
</select>
</form>
<div id="txtHint"><b>Person info will be listed here.</b></div>
<!--Main Tab Ent-->
</div>
</div>
</body>
</html>
Getuser.php
<?php
$q = intval($_GET['q']);
$result=mysql_query("select * from password WHERE id = '".$q."'");
if($result === false )
{
die(mysql_error());
}
while($row=mysql_fetch_array($result))
{
$desss=$row['tag'];
}
$res=mysql_query("select * from password WHERE tag = '".$desss."'");
if($res === false )
{
die(mysql_error());
}
?>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>username</th>
<th>Password</th>
<th>Description</th>
<th>Link</th>
</tr>
</thead>
<?php
while($row=mysql_fetch_array($res))
{
$id=$row['id'];
$name=$row['name'];
$url=$row['url'];
$uname=$row['username'];
$pass=$row['password'];
$tag=$row['tag'];
$des=$row['description'];
?>
<tbody>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $uname; ?></td>
<td><span data-tooltip aria-haspopup="true" class="has-tip" title="<?php echo $pass; ?>">View</span></td>
<td><span data-tooltip aria-haspopup="true" class="has-tip" title="<?php echo $des; ?>">Description</span></td>
<td>Link</td>
</tr>
</tbody>
<?php
}
?>
</table>
I have run your code, it is working fine.There is only one problem ,if you want to pass string then change following code on your gestuser.php
change
$q = intval($_GET['q']);
to
$q =($_GET['q']);
and change
<option value="<?php echo $id;?>"><?php echo $dess; ?></option>
to
<option value="<?php echo $dess;?>"><?php echo $dess; ?></option>
Other wise your code is working
Edit your function as following and see what string you are passing through ajax
function showUser(str) {
alert(str);
if (str=="") {
the javascript ajax function fires when the select value has changed
<select name="tagg" onchange="showUser(this.value)">
now this.value means you are passing the selected value to the javascript function
<option value="<?php echo $id;?>"><?php echo $dess; ?></option>
you have to put string in your value attribute
something like
<option value="<?php echo 'YOUR STRING HERE';?>"><?php echo $dess; ?></option>
now in your getuser.php file your query is
"select * from password WHERE id = '".$q."'"
so you will have to change the query respectively
I have two files of php.First file is of seller status report.If I click on any record then a new tab(form) opens in new window.I have used window.open in js file.
Now in second form I have a html form.I want all field fill according to id.I am not familiar how to bind data in this case.
<?php
if
(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"myquery");
if (isset($_POST['from']) && isset($_POST['from']))
{
$a=$_POST['from'];
$b=$_POST['to'];
$result = mysqli_query($con,"myquery'");
}
else {
$result = mysqli_query($con,"myquery");
}
echo "<table id='example' class='display' border='1px' cellspacing='0' width='100%'>
<thead style='background:cadetblue'>
<tr class='rowname'>
<th>Name</th>
<th>email</th>
<th>contact_no</th>
<th>state</th>
<th>city</th>
<th>TargetCity</th>
<th>ProjectName</th>
<th>Price</th>
<th>Size</th>
<th>PropertyDescription</th>
<th>PaymentPlanName</th>
<th>SaleTimeHorizon</th>
<th>PaytmentCompleted_Percentage</th>
<th>CreatedOn</th>
</tr>
</thead>";
echo"<tfoot style='display: table-header-group;'>
<tr>
<th>Name</th>
<th>email</th>
<th>contact_no</th>
<th>state</th>
<th>city</th>
<th>TargetCity</th>
<th>ProjectName</th>
<th>Price</th>
<th>Size</th>
<th>PropertyDescription</th>
<th>PaymentPlanName</th>
<th>SaleTimeHorizon</th>
<th>PaytmentCompleted_Percentage</th>
<th>CreatedOn</th>
</tr>
</tfoot>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)) {
echo "<tr id='".$row['id']."'>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['contact_no'] . "</td>";
echo "<td>" . $row['state'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['TargetCity'] . "</td>";
echo "<td>" . $row['ProjectName'] . "</td>";
echo "<td>" . $row['Price'] . "</td>";
echo "<td>" . $row['Size'] . "</td>";
echo "<td>" . $row['PropertyDescription'] . "</td>";
echo "<td>" . $row['PaymentPlanName'] . "</td>";
echo "<td>" . $row['SaleTimeHorizon'] . "</td>";
echo "<td>" . $row['PaytmentCompleted_Percentage'] . "</td>";
echo "<td>" . $row['CreatedOn'] . "</td>";
echo "</tr>";
}
echo '<a href="download.php"><img src="images/Excel-Logo.jpg">
</a>';
echo"</tbody>";
echo "</table>";
mysqli_close($con);
?>
The second file is
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Buyer Form</title>
<link rel="stylesheet" type="text/css" href="CSS/master.css" />
<link rel="stylesheet" type="text/css" href="CSS/profilepage.css">
<link rel="stylesheet" type="text/css" href="CSS/bootstrap.css">
<link rel="stylesheet" type="text/css" href="CSS/jquery.datetimepicker.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="js/datetime.js"></script>
</head>
<body>
<header class="full grey-bg btn-gryShdw pageHeader pos-r" id="header">
<div class="mr-r-15 mr-1-15" style="border-bottom:1px solid #ECECEC">
<div class="w100">
<div class="profilePic">
<img src="images/gravatar.jpg">
</div>
<div class="profileInfo w90" style="background-color:#1286f5">
<div class="f1 pos-r">
<div class="name ng-binding fl">Mayank</div>
<ul id="actions">
<li id="service" class="w30 txt-ac">Service</li>
<li id="status" class="w30 txt-ac">Status<br>Open</br></li>
<li id="user" class="w40 txt-ac">User Created On
<div class="date1">12 August</div></li>
</ul>
</div>
</div>
</div>
</div>
</header>
<div id="main" class="fl" style="width:100%">
<div id="content" class="pad5 fl mr-t5 " style="margin-bottom:25px;word-wrap:break-word ;width:20%;">
<form class="pad-l5 mr-t10 ">
<div id="name">Name</div>
<input type="text"/>
<br>
<br>
<div>Email</div>
<input type="text"/>
<br>
<br>
<div>Contact Number</div>
<input type="text"/>
<br>
<br>
<div>City</div>
<input type="text"/>
<br>
<br>
</form></div>
<div id="maindropdown" class="mr-t5 fl pad5" style="width:40%">
<div id="dropstatus" class="mr-t5 fl pad5">
<span>Status</span><br>
<select>
<option value="Gurgaon">Open</option>
<option value="Noida">Pending For Request</option>
<option value="Gurgaon">Close</option>
</select>
</div>
<div id="dropdownsub" class="mr-t5 fl pad5">
<span>SubStatus</span><br>
<select style="width:255px">
<option value="Not Known">Not Known</option>
<option value="Understood">Understood</option>
</select>
</div>
<div id="txtarea" class="mr-t10 pad-t50">Description/Notes<br>
<textarea rows="8" cols="50" style="width:100%"></textarea>
</div>
</div>
<div id="nextaction" class="mr-t6 fl pad5" style="width:35%">Next Action<br>
<div id=nextactiontxt class="mr-t5 fl pad5">
<textarea rows="3" cols="55"></textarea>
</div>
<div class="mr-t6 fl pad5 mr-t30">Next Action Date<br>
<input id="datetimepicker" type="text">
</div>
<div class="mr-t6 fl pad5 mr-t30">
<span>Next Action Responsible</span><br>
<select style="width:170px">
<option value="name1">Rohit Rahav</option>
<option value="name2">Vivek Aggarwal</option>
<option value="name3">Hitesh Singla</option>
<option value="name4">Soni</option>
<option value="name1">Mayank Vashist</option>
</select>
</div>
</div>
</div>
</body>
</html>
<?php
$mysqli=new mysqli("localhost","root","","realitycheck");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (!($stmt = $mysqli->prepare("select id,CONCAT_WS(' ', u.firstname,u.lastname) AS Name
from p_sellservices p left join users u
on p.UserId=u.id left join rc_project pt on p.ProjectId=pt.ProjectId left join p_paymentplan pp on
p.PaymentPlanId=pp.PaymentPlanId left join rc_location lc on p.LocationId=lc.LocationId"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$out_id = NULL;
$out_Name = NULL;
if (!$stmt->bind_result($out_id, $out_Name)) {
echo "Binding output parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
while ($row=mysqli_fetch_array($stmt)) {
echo'<input type="text" id="name">';
}
?>
script of window.open is here
$(document).ready(function() {
$('#example').dataTable( {
"order": [[ 3, "desc" ]],
"pageLength": 100
} );
var table = $('#example').DataTable();
$("#example tfoot th").each( function ( i ) {
var select = $('<select><option value=""></option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
var val = $(this).val();
table.column( i )
.search( val ? '^'+$(this).val()+'$' : val, true, false )
.draw();
} );
table.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
$(document).ready(function() {
$('#example').dataTable();
$('#example tbody tr').on('click', function () {
var id = $(this).attr("id");
window.open("new.php?uid="+id);
//alert( 'You clicked on '+name+'\'s row' );
} );
} );
} );
First, why are you using different jquery version at one time? That could cause errors because of changing functions from version to version.
For your Problem, you could use AJAX to send your request to your PHP-File and sending your result to Javascript to fill your HTML-Container dynamically.
See here: http://www.w3schools.com/ajax/default.ASP