gpt4 book ai didi

php - 数据表从服务器端处理在客户端搜索数据

转载 作者:行者123 更新时间:2023-11-29 20:25:21 25 4
gpt4 key购买 nike

我几乎每天都在寻找这个问题,但找不到正确的答案。我的问题是这样的:

https://www.datatables.net/examples/data_sources/server_side.html

如果您搜索 4 月 25 日的日期,则此方法不起作用,但如果您搜索 04-25,则此方法有效。

在我当前的程序中,可搜索的是数据id,而不是返回值。

现在我希望表中的所有数据都可以搜索。怎么做?提前致谢。

这是我的服务器端脚本。

$table = 'tracks_tb';

// Table's primary key
$primaryKey = 'track_id';

$columns = array(
array('db' => '`t`.`track_id`',
'dt' => 0,
'formatter' => function($a){
return '<a href="tracks-view.php?id='.$a.'">'.$a.'</a>';
},
'field' => 'track_id'
),
array('db' => '`t`.`upc`',
'dt' => 1,
'field' => 'upc'
),
array('db' => '`t`.`isrc`',
'dt' => 2,
'field' => 'isrc'
),
array('db' => '`t`.`tracktitle`',
'dt' => 3,
'field' => 'tracktitle'
),
array('db' => '`t`.`artist`',
'dt' => 4,
'formatter' => function($a){
if($a !=''){
$ab = explode(',',$a);
$artist ="";
$db = new Database();
$db->connect();
foreach ($ab as $artindex => $artvalue) {
$q_a ='SELECT fname FROM rartist WHERE id = '.$artvalue;
$r_a = $db->query($q_a);
$a_a = $db->fetch_array_assoc($r_a);
$a_id = $artvalue;
$a_name = $a_a['fname'];
if(end($ab)==$artvalue){
$artist .= '<span>'.$a_name.'</span>';
} else {
$artist .= '<span>'.$a_name.'</span>, ';
}
}
return $artist;
} else {
return $artist='';
}
},
'field' => 'artist'
),
array('db' => '`t`.`publisher`',
'dt' => 5,
'formatter' => function($p){
if($p !=''){
$aa = explode(',',$p);
$publisher ="";
$db = new Database();
$db->connect();
foreach ($aa as $pubindex => $pubvalue) {
$q1 ='SELECT publisher FROM rpublisher WHERE id = '.$pubvalue;
$r1 = $db->query($q1);
$a1 = $db->fetch_array_assoc($r1);
$p_name = $a1['publisher'];
$p_id = $pubvalue;
if(end($aa)==$pubvalue){
$publisher .= '<span>'.$p_name.'</span>';
} else {
$publisher .= '<span>'.$p_name.'</span>, ';
}
}
return $publisher;
} else {
return $publisher='';
}
},
'field' => 'publisher'
),
array('db' => '`t`.`licensor`',
'dt' => 6,
'formatter' => function($lcs){
if($lcs != ''){
$al = explode(',',$lcs);
$licensor ="";
$db = new Database();
$db->connect();
foreach ($al as $licindex => $licvalue) {
$q_l ='SELECT licensor FROM rlicensor WHERE licensor_id = '. $licvalue;
$r_l = $db->query($q_l);
$a_l = $db->fetch_array_assoc($r_l);
$l_id = $licvalue;
$l_name = $a_l['licensor'];
if(end($al)==$licvalue){
$licensor .= '<span>'.$l_name.'</span>';
} else {
$licensor .= '<span>'.$l_name.'</span>, ';
}
}
return $licensor;
} else {
$licensor = ''; return $licensor;
}
},
'field' => 'licensor'
),
array('db' => '`t`.`genre`', 'dt' => 7,
'formatter' => function($g){
if($g != ''){
$ag = explode(',',$g);
$genre ="";
$db = new Database();
$db->connect();
foreach ($ag as $genindex => $genvalue) {
$q2 ='SELECT genre FROM rgenre WHERE id = '.$genvalue;
$r2 = $db->query($q2);
$a2 = $db->fetch_array_assoc($r2);
$g_id = $genvalue;
$g_name = $a2['genre'];
if(end($ag)==$genvalue){
$genre .= '<span>'.$g_name.'</span>';
} else {
$genre .= '<span>'.$g_name.'</span>, ';
}
}
return $genre;
} else {
$genre = ''; return $genre;
}
},
'field' => 'genre'
),
array('db' => '`t`.`discno`',
'dt' => 8,
'field' => 'discno'
),
array('db' => '`t`.`trackno`',
'dt' => 9,
'field' => 'trackno'
)
);

require('class/datatables_v2.php');

$joinQuery = "FROM `{$table}` AS `t` ";
$extraCondition = "";

echo json_encode(
SSP::simple($_GET, $db->mysql_details(), $table, $primaryKey, $columns, $joinQuery, $extraCondition)
);

最佳答案

由于您给出的示例是服务器端数据表,并且发生日期不匹配的问题,因为在后端日期以“yyyy-mm-dd”格式存储(这是mysql数据库中的日期格式) )。如果您想搜索采用“yyyy-mm-dd”格式的另一种格式的日期,则必须在后端将其转换。您可以将搜索条件放在任意数量的列上。

例如:

$sSearch = $_REQUEST['sSearch'];

if($position != '')
{
$position_filter = "col1 LIKE '%".$sSearch."%' or col2 LIKE '%".$sSearch."%'";
}

关于php - 数据表从服务器端处理在客户端搜索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39340242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com