3

Ok I have a blog in php and mysql. I want to open the url in a div with show and hide javascript functions. Works fine with the rest of divs but the problem is when I click on a vanity url my web is always updated. I have a function that format this urls and i can't edit the html from this urls. I want open the content of this url on the same div that blog is it without updating the index page. How can I implement this? Here my code:

blog.php

<?php
if($_GET['id']) {

$sql = "select * from blog where id = '".$_GET['id']."' ";
$consulta = mysql_query($sql);
if (mysql_num_rows($consulta)!=0) {
    $fila=mysql_fetch_assoc($consulta);
    $fecha = date("d.m.Y", strtotime($fila['fecha']));

  echo $fila["nombre"]; 

 } 
} else {

  $sql = "select * from blog where estado = 1 order by fecha desc ";

  $consulta = mysql_query($sql);
        while ($fila=mysql_fetch_assoc($consulta)) { 

            $fecha = date("d.m.Y", strtotime($fila['fecha']));
            $url = "blog/".formato($fila["nombre"])."-".$fila["id"].".html";
            ?>

            <a id="enlace" href="<? echo $url; ?>"><?php echo $fila["nombre"]; ?></a>

            <? 
         }
    } ?>

My javascript function:

 <script type="text/javascript">
$(document).ready(function(){
    $("#enlace").click(function(){
        $('#blog').hide(); //muestro mediante id
        $('#content_blog').show(); //muestro mediante clase
     });
});

  • 3
    careful: http://en.wikipedia.org/wiki/SQL_injection possible with your 'id' qstring – JF it Jun 10 '14 at 15:52
  • One way to [sanitize](http://bobby-tables.com/) your database inputs is by using [PDO](http://www.php.net//manual/en/book.pdo.php). – 13ruce1337 Jun 10 '14 at 15:53
  • if it is just an ID then forcing the type int would be ok i think.. – vico Jun 10 '14 at 16:28

1 Answers1

0

for writing js Function on "a" tag better is use this method.

 $('body').on("click","a#enlace", function(e){
   e.preventDefault();
     ....your codes ...
 });
H.Rafiee
  • 358
  • 1
  • 9