Sunday 29 September 2013

PDO statement returns zero rows for date WHERE clause

PDO statement returns zero rows for date WHERE clause

I have two files, one is page that shows the latest additions to my site,
the other is a link to the first page.
problem: if i include a 'like' keyword instead of '=' in the sql, the
query works. however, when i use '=' (which is what i want), it returns
zero rows.
code snippets:
front-page.php
echo "On ".max($last_date).","." we had "."<a
href='/latest-txt.php?date=$md'>".count($last_posts)."</a>"." text posts!"
latest-text.php
$query = $_GET[$md];
$stmt = $db->prepare("SELECT * FROM $db_tb_name WHERE $db_tb_atr_name5 = ?
ORDER BY RAND () LIMIT 0, 15");
if($stmt->execute(array("%$query%"))){
echo "Search Results<ol>";
while($data_fetch = $stmt->fetch(PDO::FETCH_ASSOC)){
echo "<li>";
echo "<div class='tagtext'>AUTHOR: ";
echo substr($data_fetch[$db_tb_atr_name2], 0,160)," "," ";
echo "TAG: ";
echo substr($data_fetch[$db_tb_atr_name3], 0,160)," ";
//echo substr($data_fetch[$db_tb_atr_name4], 0,160)," ";
echo "</div>";
echo "<div class='tagtext'>MESSAGE: ";
echo substr($data_fetch[$db_tb_atr_name], 0,160);
echo "</div>";
//echo substr($data_fetch[$db_tb_atr_name], 0,160);
echo "</li><hr/>";
}
}
echo "</ol>";
can anybody help? thanks.

No comments:

Post a Comment