how to take data from a mysql table?

0

I need to take data from a table that has an equal field but I need that when printing that data I do not get one .... more or less something like that

 mysqli_query($conect,"SELECT * FROM asd WHERE id_p=3")
 //tnego 4 datos con id_p = 3 pro quiero que el que esta seleccionado no salga 
 //tomamos los 3 peor si apso el id del que no quiero que salga ese no salga
    
asked by Vinicio Moya Almeida 06.11.2017 в 04:09
source

1 answer

2

Use the PDO driver better.

$sql = 'SELECT * FROM contacto';
$res = $database->execute($sql);

Where database is a PDO object that is declared like this

$database = new PDO(
            'mysql:host=' . $clase::SERVER . ';dbname=' . 
            Constant::DATABASE,
            Constant::USER,
            Constant::PASS,
            array(
                PDO::ATTR_PERSISTENT => true,
                PDO::MYSQL_ATTR_INIT_COMMAND => 'set names utf8'
            )
        ); 

Execution returns true or false. If it's true, we do the following:

   if($res){
        $sentencia = $database->getStatement();
        while($fila = $sentencia->fetch()){
            $contacto = new Contacto();
            $contacto->set($fila);
            $contactos[] = $contacto;
        }
   }

Then you return the array where you save it, you go through it and you get values like a normal array.

    
answered by 06.11.2017 в 13:36