我不知道是否可能,但我必须分配“button”“id =”查询值。像:
<button type="button" class="prevbutton" id="1">Previous</button>
<button type="button" class="nextbutton">Next</button>
<?php
$poffset = 0;
if ($d > '2016-01-01') { $whereday = "AND n.timestamp >= '$d 00:00:00' AND n.timestamp < '$d 23:59:59'"; $limit = ""; } else { $limit = "LIMIT $poffset,9"; }
$term = str_replace('-', ' ', $term);
if ($term !== '') { $whereaterm = "AND (n.news_title LIKE '%$term%' OR n.news_article LIKE '%$term%')"; $limit = "LIMIT 8,9"; }
$abfrage59 = "SELECT n.news_title,n.news_id as newsId,FLOOR(TIMESTAMPDIFF(HOUR, n.timestamp, NOW())) as diff
FROM news n
WHERE n.domain_id = '2' AND n.timestamp < NOW() $whereday $whereaterm
ORDER BY timestamp DESC
$limit";
$ergebnis59 = mysql_query($abfrage59);
while ($row59 = mysql_fetch_object($ergebnis59)) {
$newstitleslug = $row59->news_title;
$newstitleslug = str_replace(' ', '-', $newstitleslug);
$newstitleslug = strtolower($newstitleslug);
?><script>$(".prevbutton").attr("id", "$row59->newsId");</script><?php
echo "<div class=\"col-sm-6 col-md-4\" style=\"padding-bottom: 15px;\">
<div class=\"item\">
<img class=\"main\" src=\"http://lolcahost/images/news/$row59->news_id.png\" />
<div class=\"text\">
<div class=\"inner\">
<a href=\"http://localhost/news-article/$newstitleslug/$row59->news_id/\" style=\"color:white;\">$row59->news_title<br />
<span class=\"date\">$row59->diff hours ago</span>
</div>
</div>
</div>
</div>";
}
?>
所以我在php查询中使用了这个,但id获取值“$ row59-&gt; newsId”,而不是查询值。有任何想法吗?提前谢谢。
?><script>$(".prevbutton").attr("id", "$row59->newsId");</script><?php
答案 0 :(得分:1)
你忘记了php标签:
<script>$(".prevbutton").attr("id", "<?=$row59->newsId?>");</script>