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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.