Welcome Guest, Not a member yet? Register   Sign In
Question about selecting from table
#1

[eluser]Davcon[/eluser]
Hi,

I have a question about basic table selection using the Active Record method.

I understand that the method for a basic table select would be:

Code:
$query = $this->db->get('mytable');

foreach ($query->result() as $row)
{
    echo $row->title;
}

However, there's something about this which bothers me and I can't find an answer.

Suppose $title happens to be empty (i.e., NULL) on a particular row. Now, let's say you wanted to replace that nothingness with a hyphon (after all, empty boxes can ruin table cells). How can you possibly do that in an elegant manner using Active Record?

I guess I could have asked the same thing about stripping slashes, string replacing or doing any kind of manipulation of the data that's being selected.

Thanks for your help.
#2

[eluser]Jaketoolson[/eluser]
Code:
SELECT if(is_null(title), '-', title) as title FROM mytable

just build your query out
#3

[eluser]Davcon[/eluser]
That's brilliant. Exactly what I needed. Thanks!

Can I just asked where you learned that coding style?
#4

[eluser]Jaketoolson[/eluser]
I'm not sure what you mean, 'coding style'. Do you mean how did I know how to do that in MySQL?

Books.




Theme © iAndrew 2016 - Forum software by © MyBB