I’m new to programming, trying to make simple cms:
A index.php display all article subject,
user click subject to show content in Fancybox, not forward to new page.
I made the PHP code works (but it’s forward to new page), and test https://stackoverflow.com/a/7844043/1775888 (this can create Fancybox content own url in address bar) works too.
I can’t figure how to combine them?
I try this before: change href in PHP, click the subject $_GET[id] not isset then can’t get the query..
Any suggestion i’d really appreciate you taking the time.
PHP (index.php)
if(isset($_GET[id])){
$id=mysql_real_escape_string($_GET["id"]);
$sql="select * from $table where id='$id'";
$query=mysql_query($sql) or die(mysql_error());
while($list=mysql_fetch_array($query)){
print"
<div class=\"contentwrap\" align=\"center\">
<div class=\"content\">\"$list[content]\"</div>
</div>
";
}
}
else{
$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\" align=\"center\">
<div class=\"subject\"><a href=\"index.php?id=$list[id]\">$list[subject]</a></div>
</div>
";
}
}
jQuery (from https://stackoverflow.com/a/7844043/1775888)
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'));
});
edit:
I change the code let the $list[content] load and display:none.
Into index.php, get message: The requested content cannot be loaded. Please try again later.
<?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>
I`m sorry, but I do not what to answer to your question. Your code just seems to be all wrong.
For example, do you even know why you have this line? –
case '<?php "#$list[id]" ?>':What do you think it is for? How do you think it executes? Is that JavaScript piece inside the php loop? If yes, then you will get multiple functions having the same name.
Besides this, if your goal is to open/close fancyBox based on the url hash, then I suggest using (soon to be released public) history helper, see this example – http://jsfiddle.net/FB7UW/show/light/ (http://jsfiddle.net/FB7UW/)