0

I checked my sql statement in phpadmin and get the results I expect but in my php I cant seem to figure out how to echo the substring from the sql statement

#blogDB is a mysqli instance and connected to the database
            $result=$blogDB->query("SELECT id, title, date, SUBSTRING(content,1,200) FROM blog ORDER BY date LIMIT 10");
            while($row=$result->fetch_object())
            {
                $template->content=<<<content
                <h1>{$row->title} - {$row->date}</h1>
                {$row->content}
    content;
                break;
            }

Everything is echoing out fine except for $row->content which is blank in php

1 Answer 1

2

The name of the field now is SUBSTRING(content,1,200), you should specify the name you want using as like this

SELECT id, title, date, SUBSTRING(content,1,200) as content FROM blog...

as here could be omitted though, so the following will work as well:

SELECT id, title, date, SUBSTRING(content,1,200) content FROM blog...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.