如何将CMS PHP代码与jQuery fancybox相结合?

如何将CMS PHP代码与jQuery fancybox相结合?,php,jquery,fancybox,Php,Jquery,Fancybox,我是编程新手,尝试制作简单的cms: index.php显示所有文章主题, 用户单击主题以在Fancybox中显示内容,而不是转发到新页面 我让PHP代码可以工作(但它将转发到新页面),测试(这可以在地址栏中创建Fancybox内容自己的url)也可以工作 我想不出如何组合它们? 我以前尝试过:在PHP中更改href,单击主题$\u GET[id]not isset,然后无法获取查询 任何建议我都非常感谢您抽出时间。 PHP(index.PHP) 编辑: 我更改代码,让$list[conte

我是编程新手,尝试制作简单的cms:

index.php显示所有文章主题,
用户单击主题以在Fancybox中显示内容,而不是转发到新页面

我让PHP代码可以工作(但它将转发到新页面),测试(这可以在地址栏中创建Fancybox内容自己的url)也可以工作

我想不出如何组合它们?

我以前尝试过:在PHP中更改href,单击主题$\u GET[id]not isset,然后无法获取查询

任何建议我都非常感谢您抽出时间。

PHP(index.PHP)


编辑:
我更改代码,让$list[content]加载并显示:无。
在index.php中,获取消息:无法加载请求的内容。请稍后再试

<?php
$sql="select * from $table order by id desc";
    $query=mysql_query($sql) or die(mysql_error());
    while($list=mysql_fetch_array($query)){
        print"
    <div class=\"subjectwrap\">
        <div class=\"subject\"><a class=\"flink\" href=\"#$list[id]\">$list[subject]</a></div>
    </div>
    ";
    print"
<div class=\"atc\" id=\"$list[id]\">
    <div class=\"contentwrap\" align=\"center\">
        <div class=\"content\">\"$list[content]\"</div>
    </div>
</div>
    ";
    }
?> 

<script type="text/javascript">
$(function(){
function showfancybox(id) {
    switch(id) {
        case '<?php "#$list[id]" ?>':

        $(id).show();

        $.fancybox({
            href: id,
            type:'inline',

            onClosed: function() {
                $(id).hide();
            }
        });
    break;
    }
}

showfancybox(location.hash);

$('a.flink').click(function(e){
    showfancybox($(this).attr('href')); //make href to id
});         
});
</script>

$(函数(){
函数showfancybox(id){
开关(id){
案例“”:
$(id.show();
$.fancybox({
href:id,
类型:'inline',
onClosed:function(){
$(id).hide();
}
});
打破
}
}
showfancybox(location.hash);
$('a.flink')。单击(函数(e){
showfancybox($(this.attr('href'));//将href设置为id
});         
});

尝试调用e.preventDefault();在调用其他函数之前的单击事件中,a标记未分配给选择器中使用的flink类


也可以在get['id']上调用intval(),而不是escape_字符串,

对不起,我不知道如何回答您的问题。你的代码似乎全错了

例如,你知道你为什么有这条线吗

案例“”:

你觉得这是干什么用的?你认为它是如何执行的?那个JavaScript片段在php循环中吗?如果是,那么您将得到多个同名函数


除此之外,如果您的目标是基于url哈希打开/关闭fancyBox,那么我建议使用(即将发布的公共)历史助手,请参见此示例-(http://jsfiddle.net/FB7UW/)

将其恢复到简单状态-在调用$.fancybox之前,您是否可以发出警报(id)-如果可以,页面上是否存在该警报?PHP中的HTML打印正确吗?您可以查看源代码并确保其全部正确吗?PHP打印所有HTML元素,条件if not isset($\u GET[id])不打印contentwrap,因此我无法在单击之前通知contentwrap,它们不存在。我是否应该调用所有内容存在并显示:index.php中无?案例“”:我在这里学习表单我做错了吗?只是在不理解为什么要这样做以及要复制什么的情况下不要复制一些代码。顺便说一句,若你们并没有注意到,那个php片段并没有回应任何东西。
function showfancybox(id) {
    switch(id) {
        case '#_name':

        $(id).show();

        $.fancybox({
            href: id,
            type:'inline',


            onClosed: function() {
                $(id).hide();
            }
        });
    break;
    }
}

showfancybox(location.hash);

$('a.flink').click(function(e){
    showfancybox($(this).attr('href')); 
});
<?php
$sql="select * from $table order by id desc";
    $query=mysql_query($sql) or die(mysql_error());
    while($list=mysql_fetch_array($query)){
        print"
    <div class=\"subjectwrap\">
        <div class=\"subject\"><a class=\"flink\" href=\"#$list[id]\">$list[subject]</a></div>
    </div>
    ";
    print"
<div class=\"atc\" id=\"$list[id]\">
    <div class=\"contentwrap\" align=\"center\">
        <div class=\"content\">\"$list[content]\"</div>
    </div>
</div>
    ";
    }
?> 

<script type="text/javascript">
$(function(){
function showfancybox(id) {
    switch(id) {
        case '<?php "#$list[id]" ?>':

        $(id).show();

        $.fancybox({
            href: id,
            type:'inline',

            onClosed: function() {
                $(id).hide();
            }
        });
    break;
    }
}

showfancybox(location.hash);

$('a.flink').click(function(e){
    showfancybox($(this).attr('href')); //make href to id
});         
});
</script>