views:

286

answers:

4

This is a quick syntax question...

I need to block out an HTML element if two SQL statements are true w/ php.

If the status = 'closed', and if the current user is logged in. I can figure out the calls, I just need to see an example of the syntax. :)

So, If SQL status=closed, and if current_user=is_logged_in()...something like that.

A: 
Chacha102
A: 
if (is_status_closed() && is_logged_in($current_user)) {
    // Block this HTML element
    elem->block();
}

is_status_closed() would return true if status is equal to "closed".

is_logged_in($current_user) would return true if the user referred to by $current_user is logged in.

The && lets you join two conditional statements together, and can be read as the word "and".

This seems to be a simple question though; is this what you are asking how to do?

Thomas Upton
Ah, beaten to it. Chacha102 seems to have a very similar answer to mine.
Thomas Upton
eh, I'm looking more for "if($this->db->status = open)..." something like that. The above answers aren't helping me...I'm a noob!
Kevin Brown
+2  A: 

I'll assume you're trying to block out a login box if the user is logged in. Here's what you'll need to do:

In the view:

<?php if ($show_login): ?>
    <!-- login box code here -->
<?php endif; ?>

In the controller's action that calls the view:

if (is_logged_in() && $this->my_model->check_something()) {
    $data['show_login'] = false;
}
else {
    $data['show_login'] = true;
}
$this->load->view('myview', $data);

In the model:

function check_something() {
    // execute the SQL statements
    // and return true/false depending on what you get
}

Refer to CodeIgniter's Active Record documentation to figure out how to setup your SQL statements.

If this isn't what you were looking for, try making your question more detailed, maybe with whatever code you have.

jimyi
+1  A: 

figured it out:

I forgot that I had already called my $data...

<?php
if ($row['status'] == 'closed' && is_logged_in()) { ?>

I feel like a dummy... :)

Kevin Brown