Answer the question
In order to leave comments, you need to log in
How can php code be shortened?
So there is js and php code
$(document).ready(function(){
$('.category').on('change', function(){
var category_list = [];
$('#filters :input:checked').each(function(){
var category = $(this).val();
category_list.push(category);
});
if(category_list.length == 0)
$('.resultblock').fadeIn();
else {
$('.resultblock').each(function(){
var item = $(this).attr('data-tag');
if(jQuery.inArray(item,category_list) > -1)
$(this).fadeIn('slow');
else
$(this).hide();
});
}
});
});
//он скрывает и показывает tr
while ( $show = mysql_fetch_array($sql)) {
if($show['cover_rf'] != 0){
echo '<tr class="resultblock" data-tag="game">';
echo '<td><form action="" method="post" class="send-id-form"><input type="submit" name="edit_now" value="Редактироать" class="submit-id"><input type="hidden" name="id_edit_now" value="'.$show['id'].'"></form><form action="" method="POST" class="send-id-delete"><input type="submit" name="delete_now" value="Удалить"><input type="hidden" name="id_delete_now" value="'.$show['id'].'"></form></td>';
echo '<td> <a href="http://'.$show['Link'].'" target="_blank">'.$show['Name'].'</a></td>';
echo '<td> <p class="desc_text">'.$cover[$show['cover_rf']].'</p></td>';
echo '<td> <p>'.$aud[$show['aud_kids']].' '.$aud[$show['aud_young']].' '.$aud[$show['aud_buis']].' '.$aud[$show['aud_par']].''.$aud[$show['aud_teach']].'</p></td>';
echo '<td> <p>'.$areas[$show['direct_educ']].' '.$areas[$show['direct_prof']].' '.$areas[$show['direct_carer']].' '.$areas[$show['direct_psy']].' '.$areas[$show['direct_buis']].' '.$areas[$show['direct_soc']].'</p></td>';
echo '<td> <p>'.$carer[$show['prof_info']].' '.$carer[$show['prof_art']].' '.$carer[$show['prof_games']].' '.$carer[$show['prof_diagnostics']].' '.$carer[$show['prof_teaching']].'</p></td>';
echo '</tr>';
}
}
//формирование таблицы tr
if($show['cover_rf'] != 0 && $show['cover_rt'] !=0){
echo '<tr class="resultblock" data-tag="game">';
echo '<td><form action="" method="post" class="send-id-form"><input type="submit" name="edit_now" value="Редактироать" class="submit-id"><input type="hidden" name="id_edit_now" value="'.$show['id'].'"></form><form action="" method="POST" class="send-id-delete"><input type="submit" name="delete_now" value="Удалить"><input type="hidden" name="id_delete_now" value="'.$show['id'].'"></form></td>';
echo '<td> <a href="http://'.$show['Link'].'" target="_blank">'.$show['Name'].'</a></td>';
echo '<td> <p class="desc_text">'.$cover[$show['cover_rf']].' '.$cover[$show['cover_rt']].' </p></td>';
echo '<td> <p>'.$aud[$show['aud_kids']].' '.$aud[$show['aud_young']].' '.$aud[$show['aud_buis']].' '.$aud[$show['aud_par']].''.$aud[$show['aud_teach']].'</p></td>';
echo '<td> <p>'.$areas[$show['direct_educ']].' '.$areas[$show['direct_prof']].' '.$areas[$show['direct_carer']].' '.$areas[$show['direct_psy']].' '.$areas[$show['direct_buis']].' '.$areas[$show['direct_soc']].'</p></td>';
echo '<td> <p>'.$carer[$show['prof_info']].' '.$carer[$show['prof_art']].' '.$carer[$show['prof_games']].' '.$carer[$show['prof_diagnostics']].' '.$carer[$show['prof_teaching']].'</p></td>';
echo '</tr>';
}
Answer the question
In order to leave comments, you need to log in
All the same, I decided with a script, for those who are interested here:
var updateRows = function()
{
var toShow = [];
$('div.tags input[type=checkbox]:checked').each(function(){
var box = $(this);
toShow.push('.' + box.attr('rel'));
});
toShow = toShow.join(', ');
$('table > tbody > tr').each(function() {
var row = $(this);
row.toggle( row.is(toShow) );
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question