我几乎每天都在寻找这个问题,但我找不到合适的答案。 我的问题是这样的:
如果您在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)
);
答案 0 :(得分:0)
由于您给出的示例是服务器端数据表,并且发生了日期不匹配的问题,因为在后端日期存储在&#39; yyyy-mm-dd&#39; format(mysql数据库中的日期格式)。 如果你想搜索另一种格式的日期,这种格式是&#39; yyyy-mm-dd&#39;比你必须在后端转换它。 并且您可以将搜索条件放在您想要的任意数量的列上。
例如:
$sSearch = $_REQUEST['sSearch'];
if($position != '')
{
$position_filter = "col1 LIKE '%".$sSearch."%' or col2 LIKE '%".$sSearch."%'";
}