Giter Site home page Giter Site logo

Comments (12)

wenzhixin avatar wenzhixin commented on May 12, 2024 1

First, you can query data from MySQL and return data you need.
For example, your.php:

$limit = $_GET['limit'];
$offset = $_GET['offset'];

... // http://www.tutorialspoint.com/php/mysql_select_php.htm

echo json_encode(array(
    'total' => 800, // select count(*) from table ...
    'rows' = $rows // select * from table limit ...
));

And then:

// http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html#server-side-pagination-table
<table data-toggle="table" data-url="your.php">
... 
</table>

Hope to help you.

from bootstrap-table.

LeonardoFonseca6 avatar LeonardoFonseca6 commented on May 12, 2024

Hi Bro,
Thanks for your answer, i have troubles, i create the php script and put de data-url="my.php" but don't show me my data info.
This is my php script...

<?php 

$sql = "SELECT nit, nom_empre, ciudad_empre, telef_empre, sitio_web, clasi_empre, dir_empre, macrosector, sector, sector2, baseM, ventas2012, activos2012, nomb_cont, cargo_cont, dep_cont, email_cont, ciudad_cont, base_cont, tel_exte, nit_cont, empre_cont FROM empresa, contactos";

function connectDB(){

        $server = "server";
        $user = "user";
        $pass = "pass";
        $bd = "bd";

    $conexion = mysqli_connect($server, $user, $pass,$bd);

        if($conexion){
            echo 'La conexion de la base de datos se ha hecho satisfactoriamente';
        }else{
            echo 'Ha sucedido un error inexperado en la conexion de la base de datos';
        }

    return $conexion;
}

function disconnectDB($conexion){

    $close = mysqli_close($conexion);

        if($close){
            echo 'La desconexion de la base de datos se ha hecho satisfactoriamente
';
        }else{
            echo 'Ha sucedido un error inexperado en la desconexion de la base de datos
';
        }  

    return $close;
}

function getArraySQL($sql){
    //Creamos la conexi贸n con la funci贸n anterior
    $conexion = connectDB();

    //generamos la consulta

        mysqli_set_charset($conexion, "utf8"); //formato de datos utf8

    if(!$result = mysqli_query($conexion, $sql)) die(); //si la conexi贸n cancelar programa

    $rawdata = array(); //creamos un array

    //guardamos en un array multidimensional todos los datos de la consulta
    $i=0;

    while($row = mysqli_fetch_array($result))
    {
        $rawdata[$i] = $row;
        $i++;
    }

    disconnectDB($conexion); //desconectamos la base de datos

    return $rawdata; //devolvemos el array
}
        $myArray = getArraySQL($sql);
        echo json_encode($myArray);
?>

Thanks men for your help...

from bootstrap-table.

wenzhixin avatar wenzhixin commented on May 12, 2024

Hi,

You can use browser open the URL(my.php) directly, and then compare with the data (http://wenzhixin.net.cn/p/bootstrap-table/docs/data1.json).

from bootstrap-table.

LeonardoFonseca6 avatar LeonardoFonseca6 commented on May 12, 2024

Hi bro,
Thanks for you answer, but i don麓t understand the porpous to do that? if my script looks like good.
I'm novice in all programation world, help me please to put the information data on your table.

Thanks again.

from bootstrap-table.

wenzhixin avatar wenzhixin commented on May 12, 2024

Hi @tiagoriba , here you need to set data-side-pagination="server".

from bootstrap-table.

tiagoriba avatar tiagoriba commented on May 12, 2024

I'm trying to get data from mysql , but table isn't receiving anything , here is my code:

index.php :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Manager</title>
<link href="includes/css/bootstrap.min.css" rel="stylesheet">
<link href="includes/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="includes/css/bootstrap-table.css">

<script src="includes/js/jquery-2.1.1.min.js"></script>
<script src="includes/js/bootstrap.min.js"></script>
<script src="includes/js/bootstrap-table.js"></script>
<script src="includes/js/bootstrap-table-pt-BR.js"></script>

</head>

<body>
<table data-toggle="table" data-url="your.php" data-cache="false" data-height="299">
    <thead>
        <tr>
            <th data-field="id">Item ID</th>
            <th data-field="name">Item Name</th>
            <th data-field="price">Item Price</th>
        </tr>
    </thead>
</table>

</body>
</html>

and my your.php

<?php
require ('/functions/classes/database.php');
$db= new Database;  

$db->query('Select * from test');
$count= $db->rowCount();
$result= $db->resultset();
$test= array(
    'total' => $count, 
    'rows' => $result,
    );

echo json_encode($test);

?>

output your. php :

{"total":3,"rows":[{"id":"1","name":"test0","price":"0"},{"id":"2","name":"test1","price":"1"},{"id":"3","name":"test2","price":"2"}]}

output index = No Results...

from bootstrap-table.

tiagoriba avatar tiagoriba commented on May 12, 2024

thanks alot for your support, working now 馃憤

from bootstrap-table.

wenzhixin avatar wenzhixin commented on May 12, 2024

You're welcome, I have updated your comment use Markdown.

from bootstrap-table.

crynos avatar crynos commented on May 12, 2024

Hi @wenzhixin . Thank you very much for the good work.

I have the same problem of tiagoriba.
No results...

here my "json.php" and the index. Can someone help me ? (I'm sorry, i don't know how to use markdown to mark the code)

json.php

include 'ARQUIVOS/functions/functions.php';

$query = "SELECT setor, nome, ramal FROM contatos ORDER BY setor ASC, nome ASC";
//Faz a conex茫o com o banco de dados e executa a query

$result = db_query($query);


while($r = mysqli_fetch_assoc($result)) {
    //$dados[]= $r['idcontatos'];
    $dados[]= $r;    
    }
    // free result set
    $result->close();


    // close connection
    mysqli_close($result);


    echo json_encode($dados);

And index.php:

<head>
<meta charset="utf-8">
<title>Manager</title>
<link href="ARQUIVOS/css/bootstrap.min.css" rel="stylesheet">
<link href="ARQUIVOS/css/estilo.css" type="text/css" rel="stylesheet" />



<script  src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="ARQUIVOS/js/bootstrap.min.js"></script>
<script src="ARQUIVOS/js/bootstrap-table/dist/bootstrap-table.js" type="text/javascript"></script>
<script src="ARQUIVOS/js/bootstrap-table/dist/locale/bootstrap-table-pt-BR.js" type="text/javascript"></script>


</head>

<body>
<table data-toggle="table"
       data-url="json.php"
       data-cache="false"
       data-side-pagination="server"
       data-height="300">
    <thead>
    <tr>
        <th data-field="setor">setor</th>
        <th data-field="nome" data-align="right">nome</th>
        <th data-field="ramal" data-align="center">ramal</th>

    </tr>
    </thead>
</table>

</body>

from bootstrap-table.

wenzhixin avatar wenzhixin commented on May 12, 2024

It seems you need to set data-side-pagination="server" to data-side-pagination="client" @crynos

from bootstrap-table.

cafi avatar cafi commented on May 12, 2024

@crynos how would be your functions.php?

from bootstrap-table.

jacean avatar jacean commented on May 12, 2024

@wenzhixin thanks,get method is ok ,but when i used post,table don't work.i don't konw why,please.

from bootstrap-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.