I have been trying to loop the entire html div part so that it creates 12 columns(twitter-bootstrap) through div tags.
In this case it shows that variable ‘dep’ is undefined..
<? php
$q1="select * from product limit 12";
$ret=mysqli_query($mysqli,$q1);
while($dep=mysqli_fetch_assoc($ret)){
?>
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<?php echo "<img src="images/home/".$dep['product_image']."" alt='".$dep['product_name']."' />";
echo "<h2>".$dep['product_price']."</h2>";
echo "<p>".$dep['product_name']."</p>";
?>
<a href="#" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>";
</div>
<div class="product-overlay">
<div class="overlay-content">
<?php echo "<h2>".$dep['product_price']."</h2>";
echo "<p>".$dep['product_name']."</p>";
?>
<a href="#" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
</div>
</div>
</div>
<div class="choose">
<ul class="nav nav-pills nav-justified">
<li><a href=""><i class="fa fa-plus-square"></i>Add to wishlist</a></li>
<li><a href=""><i class="fa fa-plus-square"></i>Add to compare</a></li>
</ul>
</div>
</div>
</div>
}
?>
I also tried this kind of format too,but it only displayed the echo keywords.In this case it displays the echo tags as if they were a part of html itself
<? php
$q1="select * from product";
$ret=mysqli_query($mysqli,$q1);
while($dep=mysqli_fetch_assoc($ret)){
echo '<div class="col-sm-4">';
echo '<div class="product-image-wrapper">';
echo '<div class="single-products">';
echo '<div class="productinfo text-center">';
echo "<img src="images/home/".$dep['product_image']."" alt='".$dep['product_name']."' />";
echo "<h2>".$dep['product_price']."</h2>";
echo "<p>".$dep['product_name']."</p>";
echo "<a href="#" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>";
echo "</div>";
echo "<div class="product-overlay">";
echo "<div class="overlay-content">";
echo "<h2>".$dep['product_price']."</h2>";
echo "<p>".$dep['product_name']."</p>";
echo "<a href="#" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class="choose">";
echo "<ul class="nav nav-pills nav-justified">";
echo "<li><a href=""><i class="fa fa-plus-square"></i>Add to wishlist</a></li>";
echo"<li><a href=""><i class="fa fa-plus-square"></i>Add to compare</a></li>";
echo "</ul>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
I cannot understand where am i going wrong.Please help..
2
Answers
Your second code has a space between the
<?
andphp
otherwise they are essentially the same thing. Or perhaps it was a formatting issue?Try:
Found 2 syntax errors, the
<? php
and oneecho"..."
. The echo syntax may get overlooked by PHP in the end, but I noticed it.