Jump to content

Ordering a Generated Image List


ecopetition

Recommended Posts

Hi there,

 

I have the following code for generating a list of smilies based on rows in a database table:

 

function generate_smiley_list()
{
global $db, $template, $config;

$sql = "SELECT *
		FROM smilies
		WHERE show_list = 1";
$result = $db->query($sql);

while($row = $db->fetch_assoc($result))
{
	$template->assign_block_vars('smilies', array(
		'SMILEY_PATH'		=>	$config['smiley_root'] .'/'. $row['image'] . $row['image_extension'],
		'SMILEY_NAME'		=>	$row['name'],
		'SMILEY_ID'			=>	$row['id']
	));
}
}

 

How can I have the array pause every 5 or so smilies and add a line break to avoid each row of smilies becoming overcrowded?

 

Thanks a lot

Eco

Link to comment
https://forums.phpfreaks.com/topic/171203-ordering-a-generated-image-list/
Share on other sites

Add a counter $i and on each iteration increment it $i++ then if ($i % 5 == 0) add line break.

 

Other option is using a combination of html and css create a list <ul> or <ol> add each item to a <li>. In CSS say ul li { display: inline } this will let the <li> act like an inline element so if it reaches the end of the box it will jump to a new line.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.