How to remove dropdown duplicate - javascript

I am fairly new to the PHP PDO world, I already know now, that the connection to the DB should be in another PHP file, but then the rest does not work :(. I have tried all day, I know I am so tired of it that I have to ask here. How do I get rid of the Duplicate? I think the duplicate is there as a result of the DB connection being in the same folder, as it is not localhost but a website. So how do I write the files out in multiple files?
In the Display.php file, I have the dropdown with HTML, followed by javascript that should trigger the table when a value from the dropdown has been chosen. Action.php is where the table is created and I tried to create a separate file for the DB connection, but then I can't concatenate the "uid" javascript value to the Action.php file.
I hoped you could help me get rid of the Duplicate of the dropdown.
Tell me if I can add more info to help.
Best regards
This I an image of the duplicate when I choose a value from the dropdown, it duplicates the dropdown, and add it below. It is meant to only show the table below.
Display.php
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL);
$host='database.*****.us-east.rds.amazonaws.com';
$db = '*****';
$port = 5432;
$username = '*****';
$password = '*****';
try {
$conn = new PDO("pgsql:host=$host;port=$port;dbname=$db;user=$username;password=$password");
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$sql ="select * from public.category";
//Prepare the select statement.
$stmt = $conn->prepare($sql);
//Execute the statement.
$stmt->execute();
//Retrieve the rows using fetchAll.
$users = $stmt->fetchAll();
?>
// show menu dropdown
<!Doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="margin-top: 50px;">
<h2 class="text-center">Væg en kategori </h2>
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4" style="margin-top:20px; margin-bottom:20px;">
<form id="submitForm">
<div class="form-group">
<select class="form-control Investment" name="Investment" id="Investment">
<option value="">Vælg Kategori</option>
<?php foreach($users as $user): ?>
<option value="<?= $user['id']; ?>"><?= $user['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
</form>
</div>
</div>
<div class="col-md-12">
<div id="show-invest">
</div>
</div>
</div>
</body>
</html>
<!---jQuery ajax load rcords using select box --->
<script type="text/javascript">
$(document).ready(function(){
$(".Investment").on("change", function(){
var InvestmentName = $(this).val();
if (InvestmentName !== "") {
$.ajax({
url : "Action.php",
type:"POST",
cache:false,
data:{InvestmentName:InvestmentName},
success:function(data){
$("#show-invest").html(data);
}
});
}else{
$("#show-invest").html(" ");
}
})
});
</script>
Action.php
<?php
// include database connection file
include_once "testSide.php";
// include_once "DBController.php";
if(isset($_POST['InvestmentName']))
{
$uid = $_POST['InvestmentName'];
}
// load records using select box jquery ajax in PHP
$qu = "select Prod.tocon as name, one.con as yield_one, five.con as yield_two, ten.con as yield_three, twenty.con as yield_four, one.st as st_one, five.st as st_two, ten.st as st_three, twenty.st as st_four, one.top as top_one, five.top as top_two, ten.top as top_three, twenty.top as top_four;";
$result = $conn->query($qu);
if (!$result) {
trigger_error('Invalid query:' . $conn->error);
}
$output = '';
if ($result->rowCount() > 0) {
$output .= "<table class='table table-hover table-border'>
<thead>
<tr>
<th>Name</th>
<th>Afkast sidste år</th>
<th>Genst sidste 5 år</th>
<th>Genst stidste 10 år</th>
<th>Genst sidste 20 år</th>
<th>SR sidste år</th>
<th>SR 5 år</th>
<th>SR 10 år</th>
<th>SR 20 år</th>
<th>DD sidste år</th>
<th>DD 5 år</th>
<th>DD 10 år</th>
<th>DD 20 år</th>
</tr>
</thead>";
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tbody>
<tr>
<td>{$row["name"]}</td>
<td>{$row["yield_one"]}</td>
<td>{$row["yield_two"]}</td>
<td>{$row["yield_three"]}</td>
<td>{$row["yield_four"]}</td>
<td>{$row["st_one"]}</td>
<td>{$row["st_two"]}</td>
<td>{$row["st_three"]}</td>
<td>{$row["st_four"]}</td>
<td>{$row["top_one"]}</td>
<td>{$row["top_two"]}</td>
<td>{$row["top_three"]}</td>
<td>{$row["top_four"]}</td>
</tr>";
}
"</tbody>";
$output .= "</tbody></table>";
echo $output;
}else{
echo "No records found";
}
?>

I fixed it by moving the database connector in an isolated file. So it did not call it self in the same PHP file. Now i then call the DB from the other files with include_once

Related

How to display a json array in html table

Hi I am new to javascript/JS or jquery . All i know is to code in php but i want to learn JS too.
My code didnt diplay the get data from json_encode to HTML TABLE.
please help me to do this. I search all way how to that. but they always use like var but when i try to do the same i didnt display anything so i start again from basics.
what i want is to display the data get from process.php json_encode into my html table TBODY part only not the whole table.
please correct me if there are something missing.(i.e jquery plugin? where to download please)
below are my code.
For Index.html
<html>
<head>
<title>LEARN AJAX</title>
<style type="text/css">
#mytable,td{
border:0px solid blue;
}
</style>
</head>
<body>
<table>
<thead>
<th>ID No.</th>
<th>Full Name</th>
<th>Address</th>
</thead>
<tbody>
<!--*/data should go Here-- >
<!--Data from process.php-->
</tbody>
</table>
</body>
</html
For Process.php
<?php
include ('connection.php');
if (mysqli_connect_errno()) {
die('Could not connect: ' . mysql_error());
}
$return_arr = array();
$sql="SELECT * FROM members";
if ($result = mysqli_query( $conn, $sql )){
while ($row = mysqli_fetch_array($result))
{
$row_array['id'] = $row['id'];
$row_array['name'] = $row['fname'];
$row_array['address'] = $row['ad'];
array_push($return_arr,$row_array);
}
}
//echo json_encode($return_arr);
$result = json_encode($return_arr);
?>
For my DB connection:
<?php
//for MySQLi OOP
$conn = new mysqli('localhost', 'root', '', 'mydatabase');
if($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
?>
In your tbody just loop through the result you get from php:
<tbody>
<?php
foreach ($result as $value) {
echo "<tr><td>"+$value['id']+"</td><td>"+$value['fname']+"</td><td>"+$value['ad']+"</td></tr>";
}
?>
</tbody>

How to edit and delete records of MySQL database without refreshing?

I am new to ajax, I am trying to view, add, edit and delete data of mysql database without refreshing the tab or in other words using ajax on this table:
I have done the view part, *edited but I can not figure out how to edit or delete *. I know it is a very long task, but I have found no solution on the internet.. Thanks in advance
HTML Code:
<html>
<head>
<title>View Data Without refresh</title>
<script language="javascript" type="text/javascript" src="script/jquery-git.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
(function() {
$.ajax({
type: "POST",
url: "display.php",
dataType: "html",
success: function(response){
$("#responsecontainer").html(response);
}
});
});
});
</script>
</head>
<body>
<fieldset><br>
<legend>Manage Student Details</legend>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Class</th>
<th>Section</th>
<th>Status</th>
</tr>
</table>
<div id="responsecontainer" align="center"></div>
</fieldset>
<input type="button" id="display" value="Add New"/>
</body>
</html>
PHP Display Code:
<?php
include("connection.php");
$sql = "select * from tbl_demo";
$result=mysqli_query($db,$sql);
echo "<table class='myTable'>";
while($data = mysqli_fetch_row($result))
{
echo "<tr>";
echo "<td width='13.5%'>$data[0]</td>";
echo "<td width='21%'>$data[1]</td>";
echo "<td width='19.5%'>$data[2]</td>";
echo "<td width='24%'>$data[3]</td>";
echo "<td><span class='edit'>Edit</span> | <span
class='delete'>Delete</span></td>";
echo "</tr>";
}
echo "</table>";
?>
If your connection, sql query and php response is ok and
I want it to be automatically done
means you want run ajax on page loading. Then, Output of php should be at last instead in each iteration.
<?php
include("connection.php");
$sql = "select * from tbl_demo";
$result=mysqli_query($db,$sql);
$output = "<table class='myTable'>";
while($data = mysqli_fetch_row($result))
{
$output .="<tr>";
$output .="<td width='13.5%'>$data[0]</td>";
$output .="<td width='21%'>$data[1]</td>";
$output .="<td width='19.5%'>$data[2]</td>";
$output .="<td width='24%'>$data[3]</td>";
$output .="<td><span class='edit'>Edit</span> | <span
class='delete'>Delete</span></td>";
$output .="</tr>";
}
$output .="</table>";
echo $output;
?>
To make edit/delete you need to pass or redirect page with action to other page named controller. After making changes again you need to redirect index/view data page or use ajax if you don't want to refresh/redirect page.

Increment value in database on generated button click

What I want to be able to do:
I have a page setup so that a table is populated with values from the database. I also generate a button for each of the rows on the table. The button is connected to the database to a field called status. It is initially at 0. When the button is clicked, I want to be able to update this value by incrementing it by 1.So after the button is clicked on the webpage, the database status value is incremented by 1.
I have tried using AJAX for this, but I havent seemed to have much luck.
view.php (Where the table is populated from the database)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>View</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
</head>
<body>
<?php
include 'php/connect.php';
include 'php/status.php';
function getStatus($num){
$status = "";
switch ($num) {
case ($num == 0):
$status = "Pending";
case ($num == 1):
$status = "Completed";
default:
$status = "Pending";
}
return $status;
}
?>
<div class="container">
<div class="row">
<div class="col-md-12 center-block">
<h1>View the Commissions</h1>
<div class="panel panel-default">
<div class="panel-heading">Commissions</div>
<div class="panel-body">
<p></p>
</div>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Alias</th>
<th>Description</th>
<th>Price</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($connect, "SELECT * FROM orders") or die(mysql_error());
while ($row = mysqli_fetch_array($query)) {
echo "<tr>";
echo "<th scope=\"row\">";
echo $row['orderID'];
echo "</th>";
echo "<th>".$row['alias']."</th>";
echo "<th>".$row['description']."</th>";
echo "<th>$".$row['price']."</th>";
echo "<th><button type=\"button\" class=\"btn btn-default btn-info\" name=\"" .$row['orderID']. "\">".getStatus($row['status'])."</button></th>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
</script>
</html>
As you can see, for each row in the database the table is populated. Here is an image of the webpage:
I did have this code for the AJAX. It did give me the correct output in the console of the browser, but I wasnt able to get this value into the process.php page
$.ajax({
url: 'php/process.php',
type: 'POST',
data: {
orderID: obj.id
},
success: function (data) {
console.log(data);
}
});
How would I have it so that as soon as the button is clicked, it updates the value and refreshes the page. Any help would be greatly appreciated
TLDR; When I click the "Pending" button, a value in the database is incremented by 1.
Your getStatus() function didn't have break statement. for simple POST use $.post. I have added .status class to your button to use it as selector with jQuery
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>View</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
</head>
<body>
<?php
include 'php/connect.php';
include 'php/status.php';
// fixed this function by adding break and removing $num from case statement
function getStatus($num)
{
$status = "";
switch ($num) {
case 0:
$status = "Pending";
break;
case 1:
$status = "Completed";
break;
default:
$status = "Pending";
}
return $status;
}
?>
<div class="container">
<div class="row">
<div class="col-md-12 center-block">
<h1>View the Commissions</h1>
<div class="panel panel-default">
<div class="panel-heading">Commissions</div>
<div class="panel-body">
<p></p>
</div>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Alias</th>
<th>Description</th>
<th>Price</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($connect, "SELECT * FROM orders") or die(mysql_error());
while ($row = mysqli_fetch_array($query)) : ?>
<tr>
<th scope="row"><?php echo $row['orderID']; ?></th>
<th><?php echo $row['alias']; ?></th>
<th><?php echo $row['description']; ?></th>
<th><?php echo $row['price']; ?></th>
<th>
// added .status class here
<button type="button" class="btn btn-default btn-info status"
name="<?php echo $row['orderID']; ?>"><?php echo getStatus($row['status']); ?></button>
</th>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
// the AJAX for updating the status
$('.status').on('click', function () {
var id = $(this).attr('name');
var btn = $(this);
$.post('php/process.php', {orderId: id}, function (response) {
var res = JSON.parse(response);
if (res.results == true) {
btn.html('Completed');
}
})
})
</script>
</html>
In php/process.php
<?php
include 'php/connect.php';
if (isset($_POST['orderId'])) {
$orderId = $_POST['orderId'];
$sql = "UPDATE `orders` SET `status`= 1 WHERE `orderID` = $orderId";
if (mysqli_query($connect, $sql)) {
echo json_encode(['results' => true]); // when update is ok
}else {
echo json_encode(['results' => false]); // when update fail
}
}

display Value from database based on Checkbox checked on the same form

I am trying to populate the value of the first name from the database based on the checkbox checked.
below is the form , which populates all the table data added in database. by selecting anyone of checkbox and click on update, it should display an alert displaying the first name which is queried from database of that row-id and then redirect to another page
i tried using method=get in form.
Right now I am stuck on how to fix the following error that I'm getting:
<Undefined index: users on line 98>
here is my code
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
<style>
html {
background-image: url("WDF_2493417.jpg");
background-size: 100% 100%;
background-repeat: no-repeat;
background-position: center;
}
html {
margin: 0;
padding: 0;
height: 100%;
}
</style>
</head>
<body>
<?php
// php populate html table from mysql database
$conn = mysqli_connect("localhost","root","");
mysqli_select_db($conn, "my_db");
$result = mysqli_query($conn,"SELECT * FROM ijob ORDER BY userId DESC");
?>
<div class="form-style-1">
<form name="frmUser" method="post" action="">
<div style="width:1200px;">
<table border="0" cellpadding="10" cellspacing="1" width="1200" class="tblListForm" align="center">
<tr class="listheader">
<td></td>
<th>first name</th>
<th>last name</th>
<th></th>
</tr>
<?php
$i=0;
$j=1;
while($row = mysqli_fetch_array($result)) {
if($i%2==0){
$classname="evenRow";
} else {
$classname="oddRow";
}
?>
<tr class="<?php if(isset($classname)) { echo $classname; }?>">
<td>
<input type="checkbox" name="users" value="<?php echo $row["userId"]; ?>" >
</td>
<td><?php echo $row["fname"]; ?></td>
<td><?php echo $row["lname"]; ?></td>
<th colspan="4">
<input type="button" name="update" class="button" value="Apply" onClick="checkAddress(this);" />
</th>
</tr>
<?php
$i++;
$j=$i+1;
}
$conn->close();
?>
</table>
</div>
</form>
</div>
</body>
<script>
function checkAddress()
{
if (document.querySelector('form[name="frmUser"] input[type="checkbox"]:checked')) {
if(!empty($_POST['users'])){
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$num_var= " ";
$num_var = mysqli_real_escape_string($conn,$_POST['users']); // getting error on this Line.
$query = "SELECT fname FROM ijob WHERE userId='$num_var'";
$result = mysqli_query($conn,$query);
if (!$result) {
echo 'MySQL Error: ' . mysqli_error($conn);
exit;
}
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$fnames[] = $row['fname'];
?>
alert("Hello <?php echo $fnames;?>");
<?php
}
}
$conn->close();
?>
}
document.frmUser.action = "form.php";
document.frmUser.submit();
} else {
alert("Pl select checkbox which You wish to Apply ");
}
}
</script>
</html>
Your PHP opening and closing tags within your <script></script> are not in the right place.
1. You have a PHP opening tag (<?php) after this if-statement
if(!empty($_POST['users'])){
<?php
it should be before the if-statement
<?php
if(!empty($_POST['users'])){
Your PHP closing tag (?>) is before the last }
?>
}

jQuery's localtime plugin failed while loading content via ajax

I am using PHP & MySQL along with AJAX & jQuery to show contents from my database table.
PHP: serverside language as usual.
jQuery: to convert UTC time to local time based on user location. Thanks to jQuery localtime plugin :)
AJAX: to show contents of page2 into page1 on selecting a value from a drop down menu
Total no of pages: 2
Page1.php
I have an HTML table to which I show contents of all users. One of the values fetched from database is a UTC datetime variable.
To convert it into user's local time, I simply used a jQuery plugin. All that I had to do was add
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.localtime-0.5.js"></script>
<script type="text/javascript">$.localtime.setFormat("yyyy-MM-dd HH:mm:ss");</script>
the above given files & then add a span <span class="localtime"> </span> in my table & echo the datetime variable into it. Viola! UTC time is now converted into user's local time.
In that same page, I have a dropdown menu showing list of all users from my database table. ANd on the onchange property of the drop down menu, I have called an AJAX function. This function will pass the username to page2.php & database opertaions are done in page2.php & results corresponding to that user is calculated & shown into an HTML table similar like to the HTML table I have in page1.php.
But in this table, UTC remains as such even though I tried adding the jQuery files in that page also. Why the jQuery localtime plugin didn't convert UTC time in page2 to localtime when it did the same in page1???
Here are two screen shots.
Page 1 before AJAX content loaded
Page1 after AJAX content loaded
Page1:
<html>
<head>
<title>Converting UTC time to Local time</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.localtime-0.5.js"></script>
<script type="text/javascript">$.localtime.setFormat("yyyy-MM-dd HH:mm:ss");</script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script>
function value_pass_func(uname)
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()//callback fn
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("showtable").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","page2.php?variable="+uname,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
$connection = mysqli_connect('localhost','root','','dummydb') or die(mysqli_error($connection));
$query="SELECT distinct(user) FROM pagination ORDER BY id ASC";
$res = mysqli_query($connection,$query);
$count = mysqli_num_rows($res);
?>
</br>
</br>
</br>
<select id="ddl" name="ddl list" onchange="value_pass_func(this.value);">
<option selected value="">select any</option>
<?php
if($count>0)
{
while($row=mysqli_fetch_array($res))
{
$now=$row['user'];
?>
<option value="<?php echo $now; ?>"><?php echo $now; ?></option>
<?php
}
}
?>
</select>
</br>
</br>
<?php
$query1="SELECT * FROM pagination ORDER BY id ASC";
$res1 = mysqli_query($connection,$query1);
$count1 = mysqli_num_rows($res1);
if($count1>0)
{
?>
<div id="showtable">
<table class="table table-bordered table-responsive table-striped" border="1">
<thead>
<tr >
<th>id</th>
<th>post</th>
<th>user</th>
<th>now</th>
</tr>
</thead>
<tbody>
<?php
while($row1=mysqli_fetch_array($res1))
{
$idd=$row1['id'];
$post=$row1['post'];
$username=$row1['user'];
$datetime=$row1['now'];
?>
<tr>
<td><?php echo $idd; ?></td>
<td><?php echo $post; ?></td>
<td><?php echo $username; ?></td>
<td><span class="localtime"> <?php echo $datetime; ?></span></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<?php } ?>
</body>
</html>
Page2:
<?php
$un=$_GET["variable"];
$connection = mysqli_connect('localhost','root','','dummydb') or die(mysqli_error($connection));
$query="SELECT * FROM pagination where user='".$un."' ORDER BY id ASC";
$res = mysqli_query($connection,$query);
$count = mysqli_num_rows($res);
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.localtime-0.5.js"></script>
<script type="text/javascript">$.localtime.setFormat("yyyy-MM-dd HH:mm:ss");</script>
<table class="table table-bordered table-responsive table-striped" border="1">
<thead>
<tr >
<th>id</th>
<th>post</th>
<th>user</th>
<th>now</th>
</tr>
</thead>
<tbody>
<?php
while($row=mysqli_fetch_array($res))
{
$idd=$row['id'];
$post=$row['post'];
$username=$row['user'];
$datetime=$row['now'];
?>
<tr>
<td><?php echo $idd; ?></td>
<td><?php echo $post; ?></td>
<td><?php echo $username; ?></td>
<td><span class="localtime"> <?php echo $datetime; ?></span></td>
</tr>
<?php
}
?>
</tbody>
</table>
You're loading jquery.. so I advise you to use it
The most simple answer to your question is to run this after your innerHTML replacement:
$.localtime.format(".localtime");
This will evaluate all of the elements again.
I suggest you do the following:
Use jquery's AJAX (link) to GET your table data.
Deliver your table data using JSON (link).
Personally I prefer to use Moment.js (link) to format my dates.
A basic jquery example..
Scripts on page1:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.localtime-0.5.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script>
$.localtime.setFormat("yyyy-MM-dd HH:mm:ss");
function value_pass_func(uname)
{
$.ajax({
type: "GET",
url: "page2.php",
data: { variable: uname },
dataType: html
}).done(function(data) {
$("#showtable").innerHTML = data;
$.localtime.format(".localtime");
});
}
</script>
And drop those script tags in page2.
I haven't tested that localtime script but it probably does it's thing when fired

Categories