Welcome Guest, Not a member yet? Register   Sign In
permission issue
#1

[eluser]alexaaaaaaaaaa[/eluser]
Hi, i need some help with my code, i want to let users to post only 2 articles/projects in ONE month and i don't know how i can do that ... i have the data when the article/project has been posted.
Thanks in advance.
#2

[eluser]jmadsen[/eluser]
when you click a button to go to the posting area,

1) call the db table and get a count of posts made during the time period you want

2) if the count is == 2, send them an alert/flash_session/whatever msg saying "sorry"

3) if needed, redirect them back to the main area they were before
#3

[eluser]alexaaaaaaaaaa[/eluser]
[quote author="jmadsen" date="1285420304"]when you click a button to go to the posting area,

1) call the db table and get a count of posts made during the time period you want

2) if the count is == 2, send them an alert/flash_session/whatever msg saying "sorry"

3) if needed, redirect them back to the main area they were before[/quote]
i know how it should work but i don't know how to interact with the database to interogate ...
as i sayed i have the time when it has been posted but i don't know how to use that ..
what i have been thinking is this
get the curent date into a var and then...i have to first count how many projects has been posted user X in the curent month...
if it has more then 2 i'll redirect his ...that's no problem but i need somehow to know the date of the last project and compare with the curent date...
Currently my code is something like this, i count how many projects user x has posted and if he has more then 2 it'll redirect his else it'll let him post.
#4

[eluser]jmadsen[/eluser]
you aren't telling us anything about how you are counting. please post some code so we can advise.

this is a fairly simple sql question.
#5

[eluser]alexaaaaaaaaaa[/eluser]
[quote author="jmadsen" date="1285443217"]you aren't telling us anything about how you are counting. please post some code so we can advise.

this is a fairly simple sql question.[/quote]
here's my controller in the view section i have a form where it has 3 checkboxes, if the standard project is selected the project type will be 3 wich means that in the database i have something like this

id creator_id project_type created etc

if($this->input->post('privatemsg3'))
{

$this->db->like('creator_id', $buyer_id);
$this->db->like('project_type', '3');
$this->db->from('projects');
$x = $this->db->count_all_results();
if($x == 2)
{
$this->session->set_flashdata('flash_message', $this->common_model->flash_message('error','You have allready posted two standard projects'));

redirect('info');

}
else {

$insertData['project_type'] = 3;
}
#6

[eluser]jmadsen[/eluser]
I think you are asking how to get the "where date less than 1 month old" part into your query?

if so, checkout this post:

http://ellislab.com/forums/viewthread/161642/#776549
#7

[eluser]alexaaaaaaaaaa[/eluser]
[quote author="jmadsen" date="1285481502"]I think you are asking how to get the "where date less than 1 month old" part into your query?

if so, checkout this post:

http://ellislab.com/forums/viewthread/161642/#776549[/quote]
hi thanks for the link but i was able to do something like this it didn't work
here's my code
Quote:$buyer_id = $this->loggedInUser->id;
$cond3 = $this->loggedInUser->id;

$this->db->like('project_type', '3');
$this->db->from('projects');

$days = date( 'm,Y', time() );
$cond1 = '%m,%Y';
$cond2 = $days;
$res = $this->admin_model->getProjects12($cond1,$cond2,$cond3);


in my model i have this


function getProjects12($cond1='',$cond2='',$cond3='')
{
$query = "SELECT * FROM projects WHERE FROM_UNIXTIME(created, '$cond1') = '$cond2' AND creator_id='$cond3'";

$res = $this->db->query($query);
return $res;
}
and i get this error

Not unique table/alias: 'projects'




Theme © iAndrew 2016 - Forum software by © MyBB