繁体   English   中英

使用查询值更改元素属性值

[英]change element attribute value with query value

我不知道是否可能,但我必须分配查询的“按钮”“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->newsId”,而不是查询值。 有任何想法吗? 提前致谢。

?><script>$(".prevbutton").attr("id", "$row59->newsId");</script><?php

你忘记了 php 标签:

<script>$(".prevbutton").attr("id", "<?=$row59->newsId?>");</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM