show multiple products foreach row in mysql php -
i making latest product list in php getting data database. want echo 18 latest products database. having outer html each item echoed pruducts different data. below query getting latest products
$query = mysql_query("select * devices order id desc limit 3") or die(mysql_error()); while($row=mysql_fetch_array($query))
and here html:
<div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 nopadding"> <div class="device_box"> <a title="'.$row['name'].'" href="'.$row['link'].'"><img class="img-responsive" alt="'.$row['name'].'" title="'.$row['name'].'" src="'.$row['img'].'" /></a> <span> <a title="'.$row['name'].'" href="'.$row['link'].'">'.$row['name'].'</a> <br /><div class="price_small">'.$row['price'].'</div> </span> </div> </div>
and want echo 18 products using foreach loop. tried using foreach shows error.
warning: invalid argument supplied foreach()
any appriciated. thanks.
don't assign $row $data $data[] = $row. while loop can sort problem, don't go foreach. use this:
$query = mysql_query("select * devices order id desc limit 3") or die(mysql_error()); while($row=mysql_fetch_array($query)){ ?> <div class="col-xs-6 col-sm-4 col-md-3 col-lg-2 nopadding"> <div class="device_box"> <a title="<?php echo $row['name'] ?>" href="<?php echo $row['link'] ?>"><img class="img-responsive" alt="<?php echo $row['name'] ?>" title="<?php echo $row['name'] ?>" src="<?php echo $row['img'] ?>" /></a> <span> <a title="<?php echo $row['name'] ?>" href="<?php echo $row['link'] ?>"><?php echo $row['name'] ?></a> <br /><div class="price_small"><?php echo $row['price'] ?></div> </span> </div> </div> <?php } ?>
Comments
Post a Comment