Jump to content

tweak to news function?


delphi123

Recommended Posts

Hi everyone,

 

I've got a news script pulling articles onto my frontpage, however now I'm wanting to use this elsewhere I'm trying to make a function that'll let me input a series of variables in different places on the site to render the news in different ways.

 

I'm thinking of making a function with variables like this:

function getNews($no_of_news,$category,$columns,$rows)

 

However what I'm struggling with is how I can do the rows/columns?

 

If I choose getNews(6,art,3,2), I'd want it to render a table with 6 news items from the 'art' category three columns and two rows of news.

 

Likewise if I chose getNews(5,sport,1,5) I'd expect it to render a single column with five rows with news items from the sport category.

 

It's just really the echoing of the HTML that I'm struggling with... can anyone shed some light on how they'd do this?

 

 

 

<?php
function getNews($number_of_news,$category,$rows,columns){

$query = ("SELECT news_id, category, title, text, img_url, linkto, ext_url, DATE_FORMAT(date,'%d %M, %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 1,$no_of_news") or DIE ("Can't retrieve");
$result=@mysql_query($query) or die("Error in News");


if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if ($row['ext_url'] == 1)
	{$ext_url = 'target="_blank"';}
else 
	{$ext_url = '';}
echo '
	<td valign="top" align="center"  class="glow">
		<a href="'.$row['linkto'].'" '.$ext_url.'>
		<img height=88px width=146px src="'.$site.'content/news/images/'.$row['img_url'].'" alt="'.$row['title'].'" class="newscategory_'.$row['category'].'"/>
		</a><br />
		'.$row['category'].' | 
		<span class="newscategory">
		<a href="'.$row['linkto'].'">'.$row['title'].'</a>
		</span><br />
				<span class="news_text">'.$row['text'].'</span>
	</td>
';
}

}

}
?>

Link to comment
https://forums.phpfreaks.com/topic/81678-tweak-to-news-function/
Share on other sites

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.