【发布时间】:2014-12-09 14:17:36
【问题描述】:
我不确定我的查询是否正确,但我只是 PHP 和 postgresql 的初学者,因此我的代码。
我想要完成的是使用日期选择器进行搜索,它将提供来自日期的数据:
<?php
$output = '';
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$query = ("SELECT trees.tree_type,tree_solds.transaction_id,tree_solds.actual_height,tree_solds.selling_height,tree_solds.sub_total,transactions.date_purchased FROM tree_solds
left join trees on tree_solds.tree_id = trees.id
left join transactions on transactions.id = tree_solds.transaction_id
WHERE date_purchased LIKE $searchq ");
$result = pg_query($query);
if (!$result) {
echo "Problem with query " . $query . "<br/>";
echo pg_last_error();
exit();
}
$count = pg_num_rows($result);
if ($count == 0) {
$output = 'No Data on that date!';
} else {
while ($row = pg_fetch_array($result)) {
$output .= printf ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", htmlspecialchars($myrow['transaction_id']), htmlspecialchars($myrow['date_purchased']), htmlspecialchars($myrow['tree_type']), htmlspecialchars($myrow['actual_height']), htmlspecialchars($myrow['selling_height']), number_format($myrow['sub_total'], 2));
}
}
}
?>
HTML 表单
<form action="location4.php" method="post">
<input type="text" class="span2" name="search" value="" data-date-format="yyyy-mm-dd" id="dp2">
<button type="submit" class="btn btn-default">Submit</button>
</form>
<?php print("$output");?>
不断收到此错误并且没有结果。
警告:pg_query():查询失败:错误:运算符不存在: 没有时区的时间戳 ~~ 整数 LINE 4: ... WHERE date_purchased LIKE 2014-... ^ 提示:没有运算符与给定的匹配 名称和参数类型。您可能需要添加显式类型转换。 在 /Applications/MAMP/htdocs/xmastool/location4.php 第 50 行问题 带查询 SELECT trees.tree_type,tree_solds.transaction_id,tree_solds.actual_height,tree_solds. sell_height,tree_solds.sub_total,transactions.date_purchased FROM tree_solds left 加入tree_solds.tree_id = trees.id left 在 transactions.id = tree_solds.transaction_id WHERE 上加入交易 date_purchased LIKE 2014-12-07 错误:运营商不存在: 没有时区的时间戳 ~~ 整数 LINE 4: ... WHERE date_purchased LIKE 2014-... ^ 提示:没有运算符与给定的匹配 名称和参数类型。您可能需要添加显式类型转换。
【问题讨论】:
-
您是否要考虑日期并忽略小时、分钟和秒来匹配时间戳?
-
只匹配我所追求的日期,没有小时、分钟和秒。
标签: php postgresql search