Execute two different functions

1

I am faced with the need to execute two different functions, one of them carries a href which is where I get the ID from a mysql table and the other function is the one that eliminates that record. I do not know much about the truth and this code is taken out by looking through the internet and editing a bit. my question is ... how can I call the function in the href and that it acts as a button, if the function the other is dissimilar?

Likewise I leave my code in case someone can help me.

PS: I do not want to execute the delete function in another file, I want to do it this way.

    $sql = "SELECT * FROM noticias ORDER BY id ASC ";
        $resultado = $conexion->query($sql);
        while($row = mysqli_fetch_array($resultado)) 
        {
        ?>
        <tbody>
        <tr>
          <td><?php echo $row['id']; ?></td>
          <td><?php echo $row['autor']; ?></td>
          <td><?php echo $row['titulo']; ?></td>
          <td><?php echo $row['categoria']; ?></td>
          <td><?php echo $row['update']; ?></td>
          <td><a href="#">Editar</a></td>
          <td><a href="./elim.php?id=<?php echo $row ['id']; ?>">Eliminar</a></td>
        </tr>
     </tbody>
    <?php
        }
        ?>
</table>
<?php 

}

function eliminar_noticia($conexion){
        $id = $_GET['id'];

        $sql = "DELETE FROM noticias WHERE id = '$id'";
        $resultado = $conexion->query($sql);

        if ($resultado) {

         echo "El registro fue eliminado correctamente";

        } else {

         echo  "Error al eliminar el registro selecionado";

    }
    return $id;
}

    function  listar_noticias($conexion){
    ?>
 <table class="table">
    <thead>
     <tr>
        <th>ID</th>
        <th>Autor</th>
        <th>Titulo</th>
        <th>Categoria</th>
        <th>Update</th>
        <th >Editar</th>
        <th>Eliminar</th>
      </tr>
    </thead>
    <?php
$sql = "SELECT * FROM noticias ORDER BY id ASC ";
        $resultado = $conexion->query($sql);
        while($row = mysqli_fetch_array($resultado)) 
        {
        ?>
        <tbody>
        <tr>
          <td><?php echo $row['id']; ?></td>
          <td><?php echo $row['autor']; ?></td>
          <td><?php echo $row['titulo']; ?></td>
          <td><?php echo $row['categoria']; ?></td>
          <td><?php echo $row['update']; ?></td>
          <td><a href="#">Editar</a></td>
          <td><a href="./elim.php?id=<?php echo $row ['id']; ?>">Eliminar</a></td>
        </tr>
     </tbody>
    <?php
        }
        ?>
</table>
<?php 

}

function eliminar_noticia($conexion){
        $id = $_GET['id'];

        $sql = "DELETE FROM noticias WHERE id = '$id'";
        $resultado = $conexion->query($sql);

        if ($resultado) {

         echo "El registro fue eliminado correctamente";

        } else {

         echo  "Error al eliminar el registro selecionado";

    }
    return $id;
}

Greetings and thanks to everyone in advance.

PD: 2 is currently running in a file external to the function I want to use.

    
asked by Oscar Manuel Martinez Mejias 10.05.2018 в 13:19
source

1 answer

0

If I look, I think I was not clear, what I want is to execute the delete_noticia function in the href, and I do not know how to do it, just that. The line is this:

<td><a href="?$id='<?php echo $row ['id']; ?>'">Eliminar</a></td>

and I need to execute this function by pressing delete

function eliminar_noticia($conexion, $id){
    $id = $_GET['id'];

    $sql = "DELETE FROM noticias WHERE id = '$id'";
    $resultado = $conexion->query($sql);

    if ($resultado) {

     echo "El registro fue eliminado correctamente";

    } else {

     echo  "Error al eliminar el registro selecionado";

}
return $id;

}

    
answered by 10.05.2018 в 19:59