Welcome Guest, Not a member yet? Register   Sign In
Codeigniter finds resuls only on string, not on php variables!
#1

[eluser]Unknown[/eluser]
I have a very... well, strange problem! I use to write my MySQL-Queries by myself so I wrote this:

Code:
$sql = "
            SELECT
                *,
                e.caption AS 'caption_entry',
                t.caption AS 'caption_topic'
            FROM
                _blog_topics_blog_entries AS rel
            INNER JOIN
                blog_entries AS e
            ON
                rel.id_blog_entries = e.id_blog_entries
            INNER JOIN
                blog_topics AS t
            ON
                rel.id_blog_topics = t.id_blog_topics
            WHERE
                e.caption = '$arg_ref'
            ORDER BY
                t.id_blog_topics ASC
        ;";
$result = $this->db->query($sql)->result_array();

That way my $result is empty. If I replace $arg_ref by for example 'text', I get the expected result. I tested $arg_ref, it is a string and it has the value 'test'. I REALLY don't understand that. That also never happened before! Not even in the same file!

Can please anyone who might understand that problem explain me how to fix that?

- Marco.
#2

[eluser]Twisted1919[/eluser]
Code:
$sql = "
            SELECT
                *,
                e.caption AS 'caption_entry',
                t.caption AS 'caption_topic'
            FROM
                _blog_topics_blog_entries AS rel
            INNER JOIN
                blog_entries AS e
            ON
                rel.id_blog_entries = e.id_blog_entries
            INNER JOIN
                blog_topics AS t
            ON
                rel.id_blog_topics = t.id_blog_topics
            WHERE
                e.caption = ?
            ORDER BY
                t.id_blog_topics ASC
        ;";
$result = $this->db->query($sql,array($arg_ref))->result_array();
#3

[eluser]Unknown[/eluser]
[quote author="OnceMac" date="1291577513"]
[code]e.caption = '{$arg_ref}'[/quote]

Enclosing your $arg_ref variable in curly braces might work too by explicitly setting your variable within the string.
http://www.php.net/manual/en/language.ty...ng.complex




Theme © iAndrew 2016 - Forum software by © MyBB