Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to combine the CMS PHP code with jQuery fancybox?
    text
    copied!<p>I'm new to programming, trying to make simple cms:<br></p> <blockquote> <p>A index.php display all article subject,<br> user click subject to show content in Fancybox, not forward to new page.</p> </blockquote> <p>I made the PHP code works (but it's forward to new page), and test <a href="https://stackoverflow.com/a/7844043/1775888">https://stackoverflow.com/a/7844043/1775888</a> (this can create Fancybox content own url in address bar) works too.</p> <p>I can't figure how to combine them?<p><br></p> <p>I try this before: change href in PHP, click the subject $_GET[id] not isset then can't get the query..</p> <p>Any suggestion i'd really appreciate you taking the time.<p><br></p> <p>PHP (index.php)</p> <pre><code>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" &lt;div class=\"contentwrap\" align=\"center\"&gt; &lt;div class=\"content\"&gt;\"$list[content]\"&lt;/div&gt; &lt;/div&gt; "; } } else{ $sql="select * from $table order by id desc"; $query=mysql_query($sql) or die(mysql_error()); while($list=mysql_fetch_array($query)){ print" &lt;div class=\"subjectwrap\" align=\"center\"&gt; &lt;div class=\"subject\"&gt;&lt;a href=\"index.php?id=$list[id]\"&gt;$list[subject]&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; "; } } </code></pre> <p>jQuery (from <a href="https://stackoverflow.com/a/7844043/1775888">https://stackoverflow.com/a/7844043/1775888</a>)</p> <pre><code>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')); }); </code></pre> <p><br> <p> edit:<br> I change the code let the $list[content] load and display:none.<br> Into index.php, get message: The requested content cannot be loaded. Please try again later.</p> <pre><code>&lt;?php $sql="select * from $table order by id desc"; $query=mysql_query($sql) or die(mysql_error()); while($list=mysql_fetch_array($query)){ print" &lt;div class=\"subjectwrap\"&gt; &lt;div class=\"subject\"&gt;&lt;a class=\"flink\" href=\"#$list[id]\"&gt;$list[subject]&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; "; print" &lt;div class=\"atc\" id=\"$list[id]\"&gt; &lt;div class=\"contentwrap\" align=\"center\"&gt; &lt;div class=\"content\"&gt;\"$list[content]\"&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; "; } ?&gt; &lt;script type="text/javascript"&gt; $(function(){ function showfancybox(id) { switch(id) { case '&lt;?php "#$list[id]" ?&gt;': $(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 }); }); &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload