Welcome Guest, Not a member yet? Register   Sign In
Get Other data in Views
#1

[eluser]MisaghCJ[/eluser]
Hi to all.

I have been working with codeigniter since 2 months ago and during this period I had a problem that I didn't find any solution for it.

Imagine we have a monthly archive for news and we want to show it this way:

January 2011 => List of News
August 2011 => List of News
September 2011 => List of News

The news table has "month" field that stores the month of news. I get list of month by "group by" in sql and when I want to show list of news I can't do that.

Consider we want to show this 3 months in view and we draw a table for each of them. the title of table is the name of Month and the rows of table is list of last five news.

How can we show it in the view? I don't know how can I send data for view.

This Picture shows my words better : http://www.img4up.com/up2/31162532966910755015.gif
Thanks
#2

[eluser]MisaghCJ[/eluser]
anyone can help?
#3

[eluser]John_Betong_002[/eluser]
[quote author="MisaghCJ" date="1307502640"]
anyone can help?
[/quote]
 
Please supply the table structure and exact output requirements.
 
 
#4

[eluser]MisaghCJ[/eluser]
name of table : news
columns of table : news_id , title , body , month , year

Insert News :

Code:
$this->db->set('title', $title);
$this->db->set('body', $body);
$this->db->set('month', date("F"));
$this->db->set('year', date("Y"));

$this->db-insert('news');

and we want to show the list of months :

Code:
$this->db->group_by('month');
$this->db->get('news');

and we show the list of months in view :

Code:
foreach($news as $value) {
echo $value->month;
}

and my problem is here :

How can I show the list of last 3 news of every month, blow that month.

Like this picture : http://www.img4up.com/up2/31162532966910755015.gif

---------------------------------------------------------------------------

my current code is like this :

Code:
<div class="textarea">
&lt;?$news = $this->news_model->getNews(array('month' => $value->month, 'limit' => 3))?&gt;
    &lt;?if($news):?&gt;
        &lt;?foreach ($news as $nvalue):?&gt;
            <ul><li id="archiveList">&lt;?=anchor(base_url().'news/show/'.$nvalue->news_id, $nvalue->title)?&gt;</li></ul>
        &lt;?endforeach?&gt;
    &lt;?endif?&gt;
</div>

But I don't want to use news model in view directly. I want to send all data from controller.
#5

[eluser]InsiteFX[/eluser]
Code:
$data = array(
    'title' => $title,
    'body'  => $body,
    'month' => date('F'),
    'year'  => date('Y')
);

$this->db->insert('news', $data);

InsiteFX
#6

[eluser]MisaghCJ[/eluser]
Dear InsiteFX,

That was example! my problem is another thing. anyway thanks for your point.
#7

[eluser]John_Betong_002[/eluser]
The date setting creates problems when trying to do anything constructive. It is far better to save the date as a MYSQL->TimeStamp;

Check this out - complete with source code:

http://johns-jokes.com/misaghcj
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB