‘Read the full entry’ issues Jul26 '04
I’ve been asking around, and I have yet to receive an answer. I need to know how some blogs allow for only a brief "snippet" of their entry to be shown on the front page, much like I do.
The reason I want to know how other people do it, is because the way I do is faulty. There are some big problems with it, and I need to get it corrected fast. I don’t have time to insert a new entry – only to see that it’s messed up the entire "blog" section.
What am I talking about, you wonder...?
I’m talking about the SQL query that pulls out only a certain number of characters from my entries, and displays that on screen, like you see in my blog section. This is accomplished by using a query similar to this:
SELECT my_table.*, LEFT(my_table.entry, LENGTH(my_table.entry) - LOCATE(‘ ’, REVERSE(my_table.entry), LENGTH(my_table.entry) - 300 )) FROM ...
Now, I know there has to be an easier way. The WHITE text in the query above basically says to pull out the first 300 characters in my entry, but use a space as the "break point," and not in between a word. In other words, it won’t cut you off in the middle of a word – but it will cut you off in the middle of a sentence, which is fine.
The problem is the HTML that’s included in the entry. For example, sometimes this query spits out something like this for the browser to render:
<p>The problem with cell phones is the technology is constantly getting better, so their actual "use life" is about 1 and a half years, but usually less. Have you ever used a particular cell phone longer than that?</p>
<h3>Old may still be
Notice there’s no closing </h3> tag? Sure, that’s because the query was instructed to only pull out a certain number of characters, and quite bluntly – some characters don’t make the cut. And HTML is treated as plain characters, just like any other.
This has happened many times so far, on this site, and I’ve had to adjust that 300 number, to make it larger, or smaller, until all of a particular HTML tags would be showing. It’s happened with <img> tags, too.
I think, perhaps, I just need to understand MySQL better, when it comes to inserting data into a TEXT field type. Unless someone knows a quick way to resolve this...
Categories: SQL ![]()
Add Feedback (view all)
Leave feedback
Very helpful, yes. Thanks. ... Read more.
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Popular Pages
- Fast rounded corners in Photoshop (7387 recent visits)
- PHP – passing variables across pages (2706 recent visits)
- JavaScript set selected on load (2273 recent visits)
- Removing all child nodes from an element (1650 recent visits)
- iPod songs out of order? (1308 recent visits)
- Firefox 3 smart address bar: wildcard search (1233 recent visits)
- Britney - Everytime piano tab (1109 recent visits)
- MySQL LEFT JOIN syntax (931 recent visits)
- Breathe Me - Sia (785 recent visits)
- Tumblr: how blogging should be (687 recent visits)
Similar Entries
- Accessible URL’s make life easier (5 recent visits)
- Send SMS with a browser? Isn’t that email? (33 recent visits)
- Don’t turn your back on Bloglines (0 recent visits)
- Find a person’s age in Excel (321 recent visits)
- Bird’s eye view? Mapquest already had that (80 recent visits)
- It’s hard remembering usernames, not passwords (2 recent visits)
Stats
4 unique visits since August 2008
Is this of any use: http://labs.silverorange.com/archives/2004/june/smarttext Of course, most of us just use blogging software like MT or WP ... Read more.