problems with HTML and PHP + Mysql

Asked

Viewed 42 times

1

I am learning the ninja arts of PHP and my code is 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 straight from the database, obviously will be the same product, but what is wrong there? (The connection to the database has already been made further up in the code).

  • What’s the mistake you’re making?

  • Parse error: syntax error, Unexpected '>' in /home/Thiago/novosite/index.php on line 45, when there is this error one appears in the place of each image saying that the variables were not found if I am not mistaken, "if I am not mistaken"

2 answers

1


I’d do it this way

 <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>
  <?
   }
  ?>
  • It worked too, thank you!

  • Okay, just give an acceptance in my answer! Thanks!

  • Yes! I’m new here and.e, it was bad.

1

Do it like this, 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]

  • Thanks guy worked perfectly ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.