Reducing amount of images shown out database PHP MySQL

Lets start with;

 echo $query_row['winkels'];

This will echo;

<td style="margin-left:3px;"><img src="logo/15.png"/></td> <td style="margin-left:3px;"><img src="logo/11.png"/></td> 

Out of my MySql Database, but on the page it will echo one image. If I put more in like example;

<td style="margin-left:3px;"><img src="logo/15.png"/></td> <td style="margin-left:3px;"><img src="logo/11.png"/></td> <td style="margin-left:3px;"><img src="logo/15.png"/></td> <td style="margin-left:3px;"><img src="logo/11.png"/></td> 

It will echo 2 images.

When I have more than 20 images shown I want to reduce it to 5 images.

How can I do that?

For example;

$winkels_inject = $query_row['winkels'];
$sub_winkels = substr($winkels_inject, 0, 191);
echo $sub_winkels;

This is perfect when trying to reduce text, but that is what it does when I use it. It reduces the image links and removes html so the images will not be shown. So no image will be shown at all.

How to fix this?

Regards, F4LLCON

Answers


It seems you have a design problem, the only thing you would need to store in a DB, is the number and then every number in a different row.

Anyway, a quick and very dirty solution:

$string_with_breaks = str_replace('td> <td', 'td>__break_here__<td', $query_row['winkels']);
$img_array = explode('__break_here__', $string_with_breaks);

// loop through array and only echo the first 5 elements
$count = 0;
foreach($img_array as $store)
{
  echo $store;
  $count++;
  if ($count > 4)
  {
     break;
  }
}

Miss (or add...) a space between the td tags and it will not work anymore...


Need Your Help

telerik RadComboBox find Returns null - why?

c# asp.net telerik find radcombobox

why the below javascript code always returns null (mean alert) ?

jQuery button response time issue while auto refreshing a DIV in every X second

php jquery database setinterval

I am using this code for refresh my main DIV in my main page (named readings.php):

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.