Change a Select mysql to a Select PDO

4

I have a Select from sources listed in a table, and I currently use this code to list them so that the user can choose the desired font.

    <select name="tipo_font_end">
    <?php
    $select = mysql_query("SELECT * FROM fontes");
    while($res = mysql_fetch_array($select)){
    ?>
    <option value="<?php echo $fontes = $res['font'];?>"><?php echo $fontes = $res['font'];?></option>
    <php? } ?>
    </select>

I'd like to know how to change to work with this PDO connection below.

    <?php
    $conn= new PDO("mysql:host=localhost;dbname=site", "root", "");

    $count = 'SELECT * FROM conteudo, cabecalho, rodape, fontes';
    $stmt = $conn->prepare($count);

    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    return $result;
    ?>

I'm inserting image from the Sources Table:

andI'mattachingcodefromtheconnection.phptobeverifiedifIdiditcorrectly.

<?php$conn=newPDO("mysql:host=localhost;dbname=pbfjacar_site", "root", "");

    $count = 'SELECT * FROM conteudo, cabecalho, rodape, fontes';
    $stmt = $conn->prepare($count);

    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    return $result;

    // Código para Select de fontes da rodapa.php

    $count = 'SELECT * FROM fontes';
    $stmt = $conn->prepare($count);

    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);
    return $result;

    foreach($result as $res){
      echo $result['font'];
    }
    ?>

Thanks in advance for all your friends.

    
asked by anonymous 09.05.2015 / 20:16

1 answer

1
<?php
$conn= new PDO("mysql:host=localhost;dbname=site", "root", "");

$count = "SELECT * FROM font";
$stmt = $conn->prepare($count);

$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

 foreach($result as $res){
      echo $res['font'];
 }
?>

Within foreach suitable for you to print properly to your need.

    
09.05.2015 / 20:25