Click here to Skip to main content
14,826,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Call the JS function in php before the database data load on the html.

What I have tried:

<pre><!DOCTYPE html>
<html lang="en">

<script  src=""></script> 
 <script  src=""></script> 
 <script  src="javascript.js"></script>

<meta charset="utf-8" />
<title>PHP & SQL Server (sqlsrv)</title>
// These are required files we must include these libraries 

<link rel='stylesheet' href="">
 <link rel="stylesheet" href="foot.css">

<body style="margin:20px auto">  
<div class="container">
<div class="row header" style="text-align:center;color:green">
<h3>Bootstrap Table With sorting,searching and paging using dataTable.js (Responsive)</h3>

<body {background-color: black;}
     height: 10%;
     margin: 10px 0px 15px 0px;
     box-shadow: 1px 1px 2px 1px grey;

<h1> Consumables Table </h1>
<form action='./test.php' method='POST'>  
Search:  <input type="text" name="id" size ='40' placeholder="Value To Search" value='<?php echo $_GET['id']; ?>' /> 
<input type="Submit"  name="search" value="Search" />  <br />

<table id="example" class="display" style="width:100%">  


ini_set('display_errors', 1);
$serverName = "APPSERVER"; 
$uid = "sa";  
$pwd = "xxxxxx";  
$databaseName = "Ramco";

$connect = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>$databaseName);

/* Connect using SQL Server Authentication. */  
$conn = sqlsrv_connect( $serverName, $connect);  
if( $conn === false )
 {die( print_r( sqlsrv_errors(), true)); 

     $id = $_POST['id'];

$sql = "SELECT * FROM consumables where Project = '$id' ";
$params = array();
$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$query = sqlsrv_query( $conn, $sql , $params, $options );

$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );

<?php while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) { ?>


               <td><div align="center">  <?php echo $row[0]; ?> </div> </td>
               <td><div align="center">   <?php echo $row[1]; ?> </div></td>
               <td><div align="center">   <?php echo $row[3]; ?> </div></td>
               <td><div align="center">   <?php echo $row[4]; ?> </div></td>
               <td><div align="center">   <?php echo $row[5]; ?> </div></td>
               <td><div align="center">   <?php echo $row[6]; ?> </div></td>
               <td><div align="center">   <?php echo $row[7]; ?> </div></td>

<?php } ?>

<?php } ?>




Updated 25-Feb-21 4:38am

1 solution

If you want to load the page before the data is loaded (from the server side) then you need to use AJAX.

AJAX is typically a javaScript function so you have your wish.

See here, if this is new to you.[^]


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900