problems with HTML and PHP + MySQL [closed]

0

I'm learning the ninja arts of PHP and my code has been giving a little headache.

<div class="container">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
    <section class="painel novidades">  
        <h2>Novidades</h2>
        <ol>

<?php
$sql = mysql_query("SELECT * FROM produtos");

while($produtos = mysql_fetch_assoc($sql)){
    echo "<li>;
            <a href=\"produto.php?\" id=<?php echo $id ?>>;
                <figure>;
                    <img class=\"foto\" src=\"img/produtos/miniatura2.png\">;
                        "<figcaption>.$exibe[nome].$exibe[valor].</figcaption>";
               </figure>;
            </a>;
         </li>";
}
?>

The intention is to show the products coming directly from the database, obviously the same product, but what is wrong there? (The connection to the database has already been made above in the code.)

    
asked by anonymous 08.01.2016 / 16:37

2 answers

1

I would do it as follows

 <div class="container">
    <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
        <section class="painel novidades">  
            <h2>Novidades</h2>
            <ol>

   <?php
   $sql = mysql_query("SELECT * FROM produtos");

   while($produtos = mysql_fetch_assoc($sql)){
   ?>
        <li>
            <a href=\"produto.php?\" id=<?php echo $id ?>
                 <figure>
                     <img class=\"foto\" src=\"img/produtos/miniatura2.png\">
                         <figcaption><? echo $exibe[nome].$exibe[valor]; ?></figcaption>
                 </figure>
             </a>
        </li>
  <?
   }
  ?>
    
08.01.2016 / 16:48
1

Do so, your code will work:

<div class="container">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
    <section class="painel novidades">  
        <h2>Novidades</h2>
        <ol>

<?php
 $sql = mysql_query("SELECT * FROM produtos");

    while($produtos = mysql_fetch_assoc($sql)){

        echo '<li>';
        echo '<a href="produto.php" id="'.$id.'">';
        echo '<figure>';
        echo '<img class="foto" src="img/produtos/miniatura2.png">';
        echo '<figcaption>'.$produtos[nome].$produtos[valor].'</figcaption>';
        echo '</figure>';
        echo '</a>';
        echo '</li>';
}
?>

See where $id is pulling. If you want to pull the product ID then you should do $produtos[id]

    
08.01.2016 / 16:58