1
我在数据库(MySql)中有两个表,一个是国家名称,另一个是用户。现在,当一些用户被添加到他/她选择的网站时,他/她是很好的。但是,由于用户数据库增长到2000个用户,我需要强制更改为服务器端数据表,以显示所有用户脚本强制冻结屏幕或网站。现在我看不到每个用户所在国家的名称,只有ID ......所以我的问题需要添加或更改以查看国家名称而不是ID。显示名称行而不是DataTable服务器端的ID
我遵循这些帖子:
这里是我的数据库:
|----------USERS-------------|
|---id-----------int---------|
|---nombres---varchar(150)---| is the user name
|---fnac-------datetime------| is the birthday
|---direccion----text--------| is the address
|---paisid--------int(3)-----| is the country id
|---foto-------varchar(50)---| is the user photo
|----------------------------|
|-----------PAISES-----------|
|---id---------int(11)-------| is the country id
|---paises---varchar(100)----| is the country name
|----------------------------|
这里我的代码(现在我不使用它因为我不知道我需要插入它的位置):
个<?php $query = "SELECT U.paisid, P.pais,
(SELECT pais FROM PAISES WHERE id = paisid)
AS pais
FROM USERS U
INNER JOIN PAISES P
ON U.paisid = P.id";
$stmt = $conn->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach($rows as $row)
{ ?><?php echo $row['pais']; ?><?php } ?>
的JS:(其中I改变示例数据部分)
$('#userTabla').dataTable({
"bProcessing": true,
"bServerSide": true,
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span12'i><'span12 center'p>>",
"sAjaxSource": "includes/server_process.php",
"aoColumns": [
{ "mData": "id" },
{ "mData": "nombres" },
{ "mData": "paisid" },
{
"mData": null,
"sClass": "center",
"sDefaultContent": "",
"fnRender": function (o) {
return '<a href="perfil.php?id=' + o.aData[0] + '" class="btn btn-success"><i class="icon-user icon-white"></i> Ver perfil</a> <a href="editar.php?id=' + o.aData[0] + '" class="btn btn-info"><i class="icon-edit icon-white"></i> Editar</a> <a id="' + o.aData[0] + '" class="btn btn-danger" href="#"><i class="icon-trash icon-white"></i> Borrar</a>'
},
"aTargets": [3]
}
],
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ registros por pag"
}
});
的server_process.php
$aColumns = array('id', 'nombres', 'paisid');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id";
/* DB table to use */
$sTable = "USERS";
/* Database connection information */
$gaSql['user'] = "dbuser";
$gaSql['password'] = "XXXXXX";
$gaSql['db'] = "dbmega";
$gaSql['server'] = "localhost";
嗨,@ volkinc是的,这是写错误,已经是int(我现在将编辑它的表)...但我怎么能显示国家的名称,而不是id当dataTable服务器端显示所有表中的用户? – user3236149
嗨。数据不足。什么是o.aData [0]?什么是perfil.php? – volkinc
我更新了答案,请看看 – volkinc