Jump to content

display result in 4 columns

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
the jil

the jil

    Newbie

  • Members
  • Pip
  • 4 posts
hey, I would like to modify the following script so that instead of displaying the result in one long list, it will show me the result in 4 columns. Is that possible?
<?php if (!defined('SITE')) exit('No direct script access allowed');



function simple_news($id=0, $limit=50)
{
	$OBJ =& get_instance();
	global $rs;
	
	if ($id == 0) return;
	
	
	$pages = $OBJ->db->fetchArray("SELECT user_format, user_offset, url, title, content, pdate 
		FROM ".PX."objects 
		INNER JOIN ".PX."users 
		WHERE status = 1 
		AND hidden = 1 
		AND section_id = '$id'
		ORDER BY title ASC, pdate DESC
		LIMIT 0,$limit");
		
	
	
	
	if (!$pages) return;
	
	$s = '';
	
		foreach ($pages as $page)	
		
		{
			
		$s .= "<p><a href='" . BASEURL . ndxz_rewriter($page['url']) . "'></a><br /><span style='color:#999;'>$when</span></p>\n";
		$s .= $page['content'];
		$s .= "<p style='margin-bottom: 16px;'><span style='color:#999;'><a href='" . BASEURL . ndxz_rewriter($page['url']) . "'/a></span></p>\n";
		
		
		}
	
	// silly bug where text processing add paragraph tags about <plug:.../>
	$s = preg_replace(array('/^<p>/i', '/<\/p>$/i'), array('', ''), trim($s));
		
	return $s;
	
	
}
?>

Edited by Orjan, 26 January 2010 - 07:52 PM.
[php] tags added


#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Lots of ways of going about it...

Could keep track of how many times you've been in the loop, $i%4 it and depending on the number put it in a different column.

#3
the jil

the jil

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks, but could you be more specific where to put the $i%4 in the code?

#4
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
$i = 0;

foreach ($pages as $page) {

$col[$i%4] .= "<p><a href='" . BASEURL . ndxz_rewriter($page['url']) . "'></a><br /><span style='color:#999;'>$when</span></p>\n";

$col[$i%4] .= $page['content'];

$col[$i%4] .= "<p style='margin-bottom: 16px;'><span style='color:#999;'><a href='" . BASEURL . ndxz_rewriter($page['url']) . "'/a></span></p>\n";

$i++;

}

echo "<table>".

"<tr>".

"<td>{$col[0]}</td>".

"<td>{$col[1]}</td>".

"<td>{$col[2]}</td>".

"<td>{$col[3]}</td>".

"</tr>".

"</table>";