bootstrap table data url populate with php - php

I have a bottstrap html table:
<table data-toggle="table" data-url="../../scripts/tags/s_displaytags.php" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar1" data-pagination="true" data-sort-name="TagName" data-sort-order="desc">
<thead>
<tr>
<th data-field="SerialNumber" data-sortable="true">Serial #</th>
<th data-field="TagName" data-sortable="true">Tag Name</th>
<th data-field="CreatedBy" data-sortable="true">Created By</th>
</tr>
</thead>
</table>
I'm trying to populate it using a PHP script s_displaytags.php. Currently im testing it so the code is:
<?PHP
$ArrayValue = array();
$ArrayValue['SerialNumber'] = 1;
$ArrayValue['TagName'] = 'test';
$ArrayValue['CreatedBy'] = 50;
echo json_encode($ArrayValue);
?>
My HTML page loads but the table values do not get loaded.
I'm not using any functions at the moment. It's just a plain PHP file returning one result row encoded s JSON.

so i just changed echo json_encode($ArrayValue); to echo json_encode(array($ArrayValue)); and it worked.

Related

Little problem with display data from local server in html table with php and sql

Today I have a little problem, with basic and maybe funny thing. Today I wanted make table with data from sql server. For that I use Xampp for that and maybe is verry common choose for that. The problem is with table because i tried to display datas with my ideas and with my knowledge and results is maybe more than what i want to do, just maybe.
Below is my scripts and I would like to mention that I make some versions of scripts and here it's just one of them.
HTML + PHP Table
<div class="centred-container table">
<table class="table-results">
<tr class="tr-table">
<th class="th-table th-univ">Product name</th>
<th class="th-table th-univ">Cod PLU</th>
<th class="th-table th-univ">Cod Intern</th>
<th class="th-table th-univ">Cod EAN/Bare</th>
<th class="th-table th-univ">Unitate</th>
<th class="th-table th-univ">Pret</th>
<th class="th-table th-univ">Stoc</th>
</tr>
<tr class="tr-table">
<?php
while ($row = mysqli_fetch_assoc($result)) {
$nameP = $row["ProductName"];
$PLUP = $row["ProductPLU"];
$ICP = $row["ProductIC"];
$EANP = $row["ProductEAN"];
$UnitP = $row["ProductUnit"];
$PriceP = $row["ProductPrice"];
$StockP = $row["ProductStock"];
echo"<td>".$nameP."</td>
<td>".$PLUP."</td>
<td>".$ICP."</td>
<td >".$EANP."</td>
<td >".$UnitP."</td>
<td >".$PriceP."</td>
<td >".$StockP."</td> <br>";
}
?>
</table>
</div>
PHP part
if (isset($_POST["submit"])) {
session_start();
include_once 'includes/dbh.inc.php';
$codePLU = $_POST["productPLU"];
$codeEAN = $_POST["productEAN"];
$codeIC = $_POST["productIC"];
$sql = "SELECT * FROM products WHERE ProductPLU ='$codePLU' OR ProductEAN = '$codeEAN' OR ProductIC = '$codeIC';";
$result = mysqli_query($conn, $sql);
}
?>
Here I want display (SELECT) data from database and and display that in html table. The problem is I tried and method with <td><?php echo $variable ?></td> where $varable = $row["column_name"] and in this situation all my data is just maybe first or the last or just one row where there should have been more because I Know my sql query have more results (rows) than one row I see.
With pasted scripts I have all my rows returned by sql query but all rows is on one line and I want to be all in a classic table.
I want just little help for my little problem. I Know is just basic problem in php site but i want some case from you, or results, where I want to try for make my table a classic table without errors same as my errors above.
Sorry for my Englesh.
The problem is with your HTML table. Need to open and close each row (<tr>) within the while loop. code below
<table class="table-results">
<tr class="tr-table">
<th class="th-table th-univ">Product name</th>
<th class="th-table th-univ">Cod PLU</th>
<th class="th-table th-univ">Cod Intern</th>
<th class="th-table th-univ">Cod EAN/Bare</th>
<th class="th-table th-univ">Unitate</th>
<th class="th-table th-univ">Pret</th>
<th class="th-table th-univ">Stoc</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($result)) {
$nameP = $row["ProductName"];
$PLUP = $row["ProductPLU"];
$ICP = $row["ProductIC"];
$EANP = $row["ProductEAN"];
$UnitP = $row["ProductUnit"];
$PriceP = $row["ProductPrice"];
$StockP = $row["ProductStock"];
echo"<tr> <td>".$nameP."</td>
<td>".$PLUP."</td>
<td>".$ICP."</td>
<td >".$EANP."</td>
<td >".$UnitP."</td>
<td >".$PriceP."</td>
<td >".$StockP."</td> </tr>";
}
?>
</table>

Laravel 7: Problems with request in registration form

Hello i have a problem with the registration in laravel.
In my register.blade.php there's a table that the user fills with a js function.
When i click on submit button i need to fetch datas from that table but i don't have a key mapping the table in the $request variable
That's the part of the code where i put the table:
<table class="table align-content-center" id="compList" name="compList">
<thead>
<tr>
<th scope="col">Competence</th>
<th scope="col">Level</th>
<th scope="col">Remove</th>
</tr>
</thead>
</table>
You should use form attribute to fetch data from it.
You can rewrite this part code as follows :
<form name="compList" class="table align-content-center" id="compList">
<thead>
<tr>
<th scope="col">Competence</th>
<th scope="col">Level</th>
<th scope="col">Remove</th>
</tr>
</thead>
</form>

I am sorting data on database but webpage doesn't take effect

I tried to sort/order data on database. I used this command:
SELECT * FROM `estates`
ORDER BY `estates`.`price` ASC
It take effect on database order. But on webpage it doesn't. How can I make it take effect on webpage too? Any idea? Thank you.
By the way I am using Laravel,
and retriving data from database with MVC
If you need to check to my page structure here it is:
<table cellspacing='0'> <!-- cellspacing='0' is important, must stay -->
<thead>
<tr>
<th width="150px">会社名</th>
<th width="150px">物件名</th>
<th width="250px">住所</th>
<th width="150px">販売価格</th>
<th width="100px">総戸数</th>
<th width="150px">専有面積</th>
<th width="100px">間取り</th>
<th width="100px">バルコニー面積</th>
<th width="100px">竣工時期</th>
<th width="100px">入居時期</th>
</tr>
<thead>
<tbody>
#foreach($estates as $estate)
<tr class="even">
<td>{{$estate->company_name}}</td>
<td>{{$estate->name}}<br/></td>
<td>{{$estate->address}}</td>
<td>{{$estate->price}}</td>
<td>{{$estate->hows_old}}</td>
<td>{{$estate->extend}}</td>
<td>{{$estate->rooms}}</td>
<td>{{$estate->balcon_m2}}</td>
<td>{{$estate->old}}</td>
<td>{{$estate->entery}}</td>
</tr>
#endforeach
</tbody>
</table>
And here is the controller:
public function sumos()
{
$estates = Estates::get();
//test
$data['estates'] = $estates;
return view('welcome', $data);
}
try to use orderBy
Estates::orderBy('price')->get();

How to set thead in vertical in datatable?

I have used jquery datatable,
HTML Code
<table id="result_table" class="display table table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Activation Status</th>
<th>Recent Login</th>
<th>Total No. of login</th>
<th>Avg No. of login/day</th>
<th>Total No. of Exports</th>
<th>Total No. of access</th>
</tr>
</thead>
<tfoot>
<tr>
<th>#</th>
<th>Username</th>
<th>Activation Status</th>
<th>Recent Login</th>
<th>Total No. of login</th>
<th>Avg No. of login/day</th>
<th>Total No. of Exports</th>
<th>Total No. of access</th>
</tr>
</tfoot>
</table>
and I have to load the table data in ajax call in JSON datatype here my PHP code
while($row = mysql_fetch_array($run_query)){
$name = $row['first_name'];
$name_string = "<a edit_id='name_".trim($name)."' href='#' onClick=\"click_today('{$name}');\" data-toggle='modal' data-target='#myModal'>{$name}</a>";
//onClick=\"click_today('{$name}');\"
$result_array[] = array($row['id'], $name_string, $row['last_name'], $row['job_title'], $row['salary'],"-","-","-");
}
echo json_encode($result_array);
acutually my result is (sample output)
but i want following image output in datatable
I don't know how to implement vertical header in jquery data table I am always using horizontal thead but now I need vertical header because of needed pls share ur suggestion or solution
It is possible to make this kind of output from server side[php] only then
to assign datatable. I had also face this problem but I make way from server side
and another way is also there you change your expected format using PIVOT Table
using database

How to make bootstrap <tr> clickable with json table data source

I am using bootstrap at http://communitychessclub.com/games.php -it's a table that displays records of chess games. I want a row to be clickable like:
<?php
echo "<tr onclick=\"location.href='basic.php?game=$game'\" >";
?>
The trouble is that the code to load and display the json table data doesn't include "TR" for displaying data; it's simply this:
<table data-toggle="table" data-url="games.json" data-cache="false"
data-search="true" data-show-refresh="true" data-show-toggle="true"
data-show-columns="true">
<thead>
<tr>
<th data-field="game" class="hidden-xs hidden-sm hidden-md
hidden-lg">#</th>
<th data-field="Date">Date</th>
<th data-field="ECO">ECO</th>
<th data-field="Event">Event</th>
<th data-field="WhiteElo">Rat.</th>
<th data-field="White">White</th>
<th data-field="BlackElo" >Rat.</th>
<th data-field="Black">Black</th>
</tr>
</thead>
</table>
I want to grab the game number (data-field="game") and
<?php
echo "<tr onclick=\"location.href='basic.php?game=$game'\" >";
?>
How could I proceed?

Categories