jenniferabel Posted June 9, 2020 Share Posted June 9, 2020 Hi guys, I have created a column in my table titled "excerpts." Just as the name suggests, I'm hoping to create excerpts of each post in my blog with a max of 100 characters. I'm using phpmyadmin, and it seems to automatically generate "0" in my excerpts column, as you'll see on my site here: https://www.visabel.ca/index.php Here is the code I have. I'm not quite sure what to write here for excerpts, so bare with me: $sql = "SELECT b.id, b.title, c.name AS category, b.tags, content, b.excerpt, photo, b.date AS pubDate, \"Jennifer\" AS author FROM blogs AS b LEFT JOIN blog_categories c ON b.category=c.id WHERE posted=\"publish\" ORDER BY DATE DESC limit 2;"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo' -------------------------- Please help! I've scoured the 'net and can't find the solution I'm looking for. Quote Link to comment https://forums.phpfreaks.com/topic/310911-excerpts-pull-content-into-column-100-characters-max/ Share on other sites More sharing options...
Barand Posted June 9, 2020 Share Posted June 9, 2020 Why store the excerpt? You can just select the first 100 chars of the content when you want to display an excerpt. $sql = "SELECT b.id , b.title , c.name AS category , b.tags , content , LEFT(content, 100) as excerpt , photo , b.date AS pubDate , 'Jennifer' AS author FROM blogs AS b JOIN blog_categories c ON b.category=c.id WHERE posted = 'publish' ORDER BY DATE DESC LIMIT 2 "; Quote Link to comment https://forums.phpfreaks.com/topic/310911-excerpts-pull-content-into-column-100-characters-max/#findComment-1578780 Share on other sites More sharing options...
jenniferabel Posted June 9, 2020 Author Share Posted June 9, 2020 42 minutes ago, Barand said: Why store the excerpt? You can just select the first 100 chars of the content when you want to display an excerpt. $sql = "SELECT b.id , b.title , c.name AS category , b.tags , content , LEFT(content, 100) as excerpt , photo , b.date AS pubDate , 'Jennifer' AS author FROM blogs AS b JOIN blog_categories c ON b.category=c.id WHERE posted = 'publish' ORDER BY DATE DESC LIMIT 2 "; Hi Barand, I tried that previously but it still didn't display my excerpt. I'm not sure what's going on... Quote Link to comment https://forums.phpfreaks.com/topic/310911-excerpts-pull-content-into-column-100-characters-max/#findComment-1578782 Share on other sites More sharing options...
requinix Posted June 9, 2020 Share Posted June 9, 2020 Have you considered that maybe the problem that should be solved is the one where it wasn't displaying the excerpt? What code did you have for that, and given that it was not displaying then what was it doing? Quote Link to comment https://forums.phpfreaks.com/topic/310911-excerpts-pull-content-into-column-100-characters-max/#findComment-1578783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.