sql >> Database teknologi >  >> RDS >> Mysql

Sql-forespørgsel tomt resultat på php-kode

prøv dette

    $query='SELECT DISTINCT publication_id FROM publications WHERE 1=1 ';
 if(isset($keyword_label) && isset($publication_year)){
 $query.=' AND (publication_key_1="'.$keyword_label.'" OR publication_key_2="'.$keyword_label.'" OR publication_key_3="'.$keyword_label.'" OR 
publication_key_4="'.$keyword_label.'" OR publication_key_5="'.$keyword_label.'" OR publication_key_6="'.$keyword_label.'" OR
publication_key_7="'.$keyword_label.'") AND publication_year="'.$publication_year.'"';
}
if(isset($publication_year)){
$query.=' AND publication_year="'.$publication_year.'"';
}
if(isset($keyword_label)){
$query.=' AND publication_key_1="'.$keyword_label.'" OR publication_key_2="'.$keyword_label.'" OR publication_key_3="'.$keyword_label.'" OR 
publication_key_4="'.$keyword_label.'" OR publication_key_5="'.$keyword_label.'" OR publication_key_6="'.$keyword_label.'" OR
publication_key_7="'.$keyword_label.'"';
}
$query.=' ORDER BY publication_year DESC';

EDIT:

prøv at ændre dette

   if(!$result) {

til dette

  if( $result == false ) { 



  1. MySQL:SyntaxError:Uventet identifikator

  2. Anvendelse af en unik datobegrænsning på TIMESTAMP-kolonnen i postgresql

  3. MySQL regexp på indekser

  4. Værelse bedste måder at oprette sikkerhedskopier til offline applikation?