delphi123 Posted December 14, 2007 Share Posted December 14, 2007 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> '; } } } ?> Quote Link to comment Share on other sites More sharing options...
delphi123 Posted December 14, 2007 Author Share Posted December 14, 2007 grr! I've tried all day and this is driving me nuts - there must be some way that you clever bods do it! ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.