Консультация по ajax запросу

Руслан Абсалямов

Кто меня может проконсультировать, почему записи не выводит коректно при фильтрации?

<script>
$(document).ready(function()
{
$("#filterForm").submit(function(e)
{
e.preventDefault();
var str = $(this).serialize();
$.ajax({
url: "TransTable.php",
type: "POST",
data: str,
success: function(data)
{
$("#TransTable").html(data);
}
});
});
});
</script>
<form id="filterForm" method="POST">
<?php
if (isset($_POST['filter'])) {
$dateStart = htmlspecialchars($_POST['fromDate']);
$dateEnd = htmlspecialchars($_POST['beforeDate']);
$idTrans=htmlspecialchars($_POST['idTrans']);
}
$transactions = filter($dateStart, $dateEnd, $typ, $categ, $account, $idTrans, $organ);
?>
<div id="controls">
<div id="filter">
<div id="dataView">
<?php dateView(); ?>
</div>
<div>
<input type="submit" name="filter" id="filterButtom" value="Фильтровать">
<label for="fromDate">От </label><input type="date" name="fromDate" id="fromDate" value="<?=$dateStart ?>" >
<label for="beforeDate">До </label><input type="date" name="beforeDate" id="beforeDate" value="<?=$dateEnd ?>" >
</div>
<div id="filterExtended">
<div id="filterTyp">
<select name="filterTyp">
<option value="" selected>Тип операции</option>
<option value="Доход">Доход</option>
<option value="Расход">Расход</option>
<option value="Перевод">Перевод</option>
</select>
</div>
<div>
<select id="filterCateg" name="filterCateg" class="filterCateg">
<option value="" selected>Категорию</option>
<?php foreach ($categoria as $categ): ?>
<option value="<?=$categ['idCateg']?>"><?=$categ['category']?></option>
<?php endforeach; ?>
</select>
</div>
<select name="filterAccount" id="filterAccount">
<option value="" selected>
Счет</option>
<?php foreach ($score as $scores): ?>
<option value="<?=$scores['idScore']?>"><?=$scores['score']?></option>
<?php endforeach; ?>
</select>
<select name="organization">
<option value="" selected>Организация</option>
<?php foreach ($organization as $organ): ?>
<option value="<?=$organ['idOrg']?>"><?=$organ['organization']?></option>
<?php endforeach; ?>
</select>
</div>
</form>
<form id="form1" method="POST" action="transactions.php">
<!--Удаление-->
<button id="delete" class="hidden" name="delete">Удалить</button>
<script>delet()</script>
<div>
<table cellpadding="2" cellspacing="0" border="0" id="table_id" class="display">
<thead>
<tr>
<th><input type="checkbox" name="cb_all" value="all" id="all"></th>
<th>Дата</th>
<th>Тип</th>
<th>Счет</th>
<th>Категория</th>
<th>Подкатегория</th>
<th>Организация</th>
<th>Сумма</th>
<th>Комментарий</th>
<th></th>
</tr>
</thead>
<tbody id="TransTable">
<?php foreach ($transactions as $transact): ?>
<tr>
<td><input type="checkbox" data-id="<?=$transact['idTrans']?>" name="check[]" class ="qwe" value="<?=$transact['idTrans']?>"></td>
<td><?=date('d.m', strtotime($transact['data']))?></td>
<td><?=$transact['typ']?></td>
<td><?=$transact['score']?></td>
<td><?=$transact['category']?></td>
<td><?=$transact['subcategory']?></td>
<td><?=$transact['organization']?></td>
<td><?=$transact['Sum']?></td>
<td><?=$transact['comment']?></td>
<td>Изменить</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</form>
<script>
allCheckbox()
sorter()
</script>

И файл где выводит ajax запрос при success

<?php
session_start();
$idUser=$_SESSION['id'];
if (isset($_POST['filter']))
{
$dateStart = htmlspecialchars($_POST['fromDate']);
$dateEnd = htmlspecialchars($_POST['beforeDate']);
$typ = htmlspecialchars($_POST['filterTyp']);
$categ = htmlspecialchars($_POST['filterCateg']);
$account = htmlspecialchars($_POST['filterAccount']);
$organ = htmlspecialchars($_POST['filterOrganiz']);
$idTrans=htmlspecialchars($_POST['idTrans']);
}
require "../verification/connect.php";
$where = [];
$where[] = isset($_POST['fromDate']) ? "t.data >='$dateStart'" : "t.data >= '".date('Y-m-01')."'";
if(!empty($_POST['beforeDate'])) $where[] = "t.data <'$dateEnd'";
if(!empty($_POST['filterTyp'])) $where[]="t.typ ='$typ'";
if(!empty($_POST['filterCateg'])) $where[]="t.idCateg ='$categ'";
if(!empty($_POST['filterAccount'])) $where[]="t.idScore ='$account'";
if(!empty($_POST['filterOrganiz'])) $where[]="t.idOrg ='$organ'";
$sqlTrans="SELECT t.idTrans, t.typ, t.data, t.Sum,t.comment, t.delet, score.score, Categoria.category, subcategory.subcategory, organization.organization
FROM transactions AS t
LEFT JOIN score ON score.idScore = t.idScore
LEFT JOIN Categoria ON Categoria.idCateg = t.idCateg
LEFT JOIN subcategory ON subcategory.idSubCat = t.idSubCat
LEFT JOIN organization ON organization.idOrg = t.idOrg
WHERE
t.idUser='$idUser' AND t.delet = '0' AND
( ".implode(' AND ', $where)." )
ORDER BY t.data ASC";
$queryTrans=mysql_query($sqlTrans) or die(mysql_error());
$transactions=array();
while($rowTrans = mysql_fetch_array($queryTrans))
{
$transactions[]=$rowTrans;
}
foreach ($transactions as $transact)
{
echo"<tr>";
echo"<td><input type='checkbox' data-id=".$transact['idTrans']." name='check[]'' class ='qwe' value=".$transact['idTrans']."></td>";
echo"<td>".date('d.m', strtotime($transact['data']))."</td>";
echo"<td>".$transact['typ']."</td>";
echo"<td>".$transact['score']."</td>";
echo"<td>".$transact['category']."</td>";
echo"<td>".$transact['subcategory']."</td>";
echo"<td>".$transact['organization']."</td>";
echo"<td>".$transact['Sum']."</td>";
echo"<td>".$transact['comment']."</td>";
echo"<td>Изменить</td>";
echo"</tr>";
}
?>

1 чел.