-1

I'm trying to make a product view page and I have a problem. I cannot understand why does not show any products etc.

<?php
include("includes/db.php");
$result = mysqli_query($conn, "SELECT * FROM products");
while ($row = mysqli_fetch_array($result))
    echo "<div class='row'>"; {

    echo "<div class='col-lg-4 col-sm-6 portfolio-item'>";
    echo "<div class='card h-100'>";
    echo "<a href='#'><img class='card-img-top' src='" . $row['thumb'] . "' alt=''></a>";
    echo "<div class='card-body'>";
    echo "<h4 class='card-title'>";
    echo "<a href='#'>" . $row['title'] . "</a>";
    echo "</h4>";
    echo "<p class='card-text'></p>";
}
echo "</div> </div> </div>";

mysqli_close($conn);
?>

Thats the php code, did I miss somewhere " or ' ? I still cannot understand where is the problem..

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

3 Answers3

1

try with this one.you have to use echo "<div class='row'>"; befor while {

<?php
include("includes/db.php");
$result = mysqli_query($conn, "SELECT * FROM products");
echo "<div class='row'>";
while ($row = mysqli_fetch_array($result))
 {

echo "<div class='col-lg-4 col-sm-6 portfolio-item'>";
echo "<div class='card h-100'>";
echo "<a href='#'><img class='card-img-top' src='" . $row['thumb'] . "' alt=''></a>";
echo "<div class='card-body'>";
echo "<h4 class='card-title'>";
echo "<a href='#'>" . $row['title'] . "</a>";
echo "</h4>";
echo "<p class='card-text'></p>";
}
echo "</div> </div> </div>";

mysqli_close($conn);
?>
pleh_pro
  • 11
  • 4
  • Even though you might have fixed the issue, why should anyone "*try this*"? Please, always write some text that explains the things you have changed, and why you changed those. – Qirel Oct 16 '17 at 07:31
0

Move first "echo" inside of the bracket:

while ($row = mysqli_fetch_array($result))
    {    
    echo "<div class='row'>"; 
    echo "<div class='col-lg-4 col-sm-6 portfolio-item'>";
    echo "<div class='card h-100'>";
    echo "<a href='#'><img class='card-img-top' src='" . $row['thumb'] . "' alt=''></a>";
    echo "<div class='card-body'>";
    echo "<h4 class='card-title'>";
    echo "<a href='#'>" . $row['title'] . "</a>";
    echo "</h4>";
    echo "<p class='card-text'></p>";
}
sskoko
  • 819
  • 6
  • 18
0

There was an error in line 5 and the while loop does start bracket properly.

<?php
include("includes/db.php");
$result = mysqli_query($conn, "SELECT * FROM products");
while ($row = mysqli_fetch_array($result)){
    echo "<div class='row'>";

    echo "<div class='col-lg-4 col-sm-6 portfolio-item'>";
    echo "<div class='card h-100'>";
    echo "<a href='#'><img class='card-img-top' src='" . $row['thumb'] . "' alt=''></a>";
    echo "<div class='card-body'>";
    echo "<h4 class='card-title'>";
    echo "<a href='#'>" . $row['title'] . "</a>";
    echo "</h4>";
    echo "<p class='card-text'></p>";
}
echo "</div> </div> </div>";

mysqli_close($conn);
?>
Dipak
  • 2,248
  • 4
  • 22
  • 55