php - Using Substr in a While loop for multiple products -


i trying show part of items details , have implemented substr while loop. works first product, second product shows '...' , not first 7 characters

while($row = mysqli_fetch_array($sql)){      $id = $row["id"];      $product_name = $row["product_name"];      $price = $row["price"];      $details = $row["details"];      if (strlen($details) > 10){         $details1 = substr($details, 0, 7) . '...';     } else {         $details1 = $details;     }     $date_added = strftime("%b %d, %y", strtotime($row["date_added"]));      $dynamiclist .= '<div class="contentimage"><a href="product.php?id=' . $id .'"><img src="images/stock_images/' . $id . '.png" alt="' . $product_name .'" width="136" height="97"></a></div>              <div class="contentdes"><strong>' . $product_name .'</strong><br>              price: £' . $price .'<br>                      ' . $details1 . '<br>                      <a href="product.php?id=' . $id .'">view product</a></div>';  } 

either make this:

  if (strlen($details) > 7){         $details1 = substr($details, 0, 7) . '...';     } 

or

 if (strlen($details) > 10){         $details1 = substr($details, 0, 10) . '...';     } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -