问题描述
我试图使用&LT送PHP变量; A>
标记并使用引导选项卡相同的PHP页面上的数据属性:
I'm trying to send PHP variables using the <a>
tag and the data attribute on the same PHP page using the Bootstrap tabs:
HTML(引导选项卡中选择):
HTML (Bootstrap tab option):
<a style='padding:20px;' href='#tab_e' data-page='$page' class='passrss' data-rssid='$rssid' data-toggle='tab'>Test</a>
PHP(存储在#tab_e标签):
PHP (stored in #tab_e tab):
$rsspassedid = GET $rssid from the a tag (data-rssid)
我想获得存储在数据rssid上点击的价值,并进一步向下在同一个PHP文件传递给一个变量,这样,当使用标签打开 #tab_e
,MySQL的声明将运行基于在$ rssid提供的值并显示查询结果。我不知道,如果任何的jQuery / AJAX将需要这一点,但有可能获得存储的数据的属性数据的&LT; A&GT;
在PHP标签?
I'd like to get the value stored in data-rssid on click and pass it to a variable further down in the same PHP file so that when the tab is opened using #tab_e
, the mySQL statement will run based on the value provided in $rssid and display the results of the query. I'm not sure if any jQuery/AJAX would be required for this but is it possible to get data stored in the data attribute of the <a>
tag in PHP?
我已经试过了分页链接,但仍然没有运气存储变量,这里是我创建XHR对象:
I've tried storing the variables in the pagination links but still no luck, here's the XHR object I created:
<script>
$(document).ready(function () {
$('.passrss').click(function () {
$('span.pass-tabe').load('tabe.php?rssid=' + $(this).data('rssid') + '&page=' + $(this).data('page'));
});
});
</script>
田部传递给一个单独的PHP文件存储在标签中的变量(<$ C C $> tabe.php ),然后使用&LT加载到浏览器;跨度类=通田部&GT;&LT; / SPAN&GT;
,至于分页 - 链接存储在tabe.php文件,但它们指回主PHP文件,因此分页失败作品如
Tabe passes the variables stored in the a tag to a seperate php file (tabe.php
) which then loads into the browser using <span class="pass-tabe"></span>
, as for pagination - the links are stored in the tabe.php file but they refer back to the main php file hence pagination fails to work e.g.
originalphpfile.php?page=$page&rssid=$rssidpassed&pageurl=$x#tab_e
注: $ rssidpassed
保存在 tabe.php
它从XHR对象,例如获取
NOTE: $rssidpassed
is stored in tabe.php
which it gets from the XHR object e.g.
$_GET['rssid']
更新2
我添加了下面那里我遇到的问题,在存储在tabe.php当下$ C $下分页:
UPDATE 2
I've added the code for pagination below where I'm having the issue at the moment which is stored in tabe.php:
$perpage = 10;
$pageurl = (isset($_GET['pageurl'])) ? (int)$_GET['pageurl'] : 1;
$start = ($pageurl - 1) * $perpage;
$pagequery = mysql_query("SELECT COUNT('topic_id') FROM topic WHERE cat_id='$page' AND topic.users_id = '$rssid'");
$pagination = ceil(mysql_result($pagequery, 0) / $perpage);
//query goes here
//pagination numbers
if($pagination >= 1){
echo "<div style='text-align:center;'><ul class='pagination'>";
for($x=1; $x<=$pagination; $x++){
echo ($x == $pageurl) ? "<li class='active'><a href='originalphpfile.php?page=$page&pageurl=$x#tab_e'>$x</a></li>":"<li><a href='originalphpfile.php?page=$page&pageurl=$x#tab_e'>$x</a></li>";
}
echo "</ul></div>";
}
当我点击分页链接,它不会加载第二个,第三个,等的结果集,因为它返回到originalphpfile.php
When I click on pagination links, it doesn't load the second, third, etc set of results as it returns to the originalphpfile.php
有没有变通方法吗?
推荐答案
解决的问题,我呼应了AJAX成田部php文件,并改变了分页HTML链接:
Issue resolved, I echoed out the AJAX into the tabe php file and changed the pagination HTML links:
tabe.php分页链接:
tabe.php pagination link:
<a href='#tab_e' class='passrssurl' data-rssid='$rsspassedid' data-url='$x' data-page='$page' data-toggle='tab'>
tabe.php回声AJAX:
tabe.php echo AJAX:
echo "<script>
$(document).ready(function () {
$('.passrssurl').click(function () {
$('span.pass-tabe').load('tabe.php?rssid=' + $(this).data('rssid') + '&page=' + $(this).data('page') + '&pageurl=' + $(this).data('url'));
});
});
</script>";
这篇关于通过PHP变量,而不在引导标签使用的href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!