It 'seems' to be grabbing the snippet from a starting place inside the cloumn for the first row returned
Are you referring to your Content field? You wanted to display x amount of characters, right?
So you're saying if you had this in your database under Content:
"See Forum Rules (below) for
more information about what
codes you are allowed to use
in your posts."
It may return something like
"or more information abo"
?? If that's the problem, I'd say it's your variables that you're using with sub_str(), $start and end. If you want to grab the first 400 characters, you'd use sub_str($string, 0, 400)
I'm guessing you would never want to start at character 30 for example, your start variable would always be 0. So then why are you defining $start like this:
$start = ($length / 2) - $padding;
It's hard to help you exactly cause I don't know what you're tryign to do nor have I seen your site and you also don't give the value for $padding in the code you posted, but that doesn't matter, you want to get $start to equal 0, and $end to equal how many characters you want to display (IE: 400). Most news article sites have something liekt his, if the full article is (taken from mysql.com)
As of MySQL Version 3.23.12, you can give hints about which index MySQL should use when retrieving information from a table. This is useful if EXPLAIN shows that MySQL is using the wrong index from the list of possible indexes. By specifying USE INDEX (key_list), you can tell MySQL to use only one of the possible indexes to find rows in the table. The alternative syntax IGNORE INDEX (key_list) can be used to tell MySQL to not use some particular index. USE/IGNORE KEY are synonyms for USE/IGNORE INDEX.
Now that's too long. So what they do is display a portion of it (IE first 400 characters), then have a link that says read full article. The portion would look something like this:
As of MySQL Version 3.23.12, you can give hints about which index MySQL should use when retrieving information from a table. This is useful if EXPLAIN shows that MySQL is using the wrong index from the list of poss. . . READ MORE
(assuming thats 400 characters long). The sub_str function for that would look something like
$portion = substr($string, 0, 400);
echo $portion " . . . <a href=full_story.php?id=" . $ROWS["id"] . "READ MORE</a>\n";
Most news site show (I think) the same amount of characters, so it would always be 0, 400 -- so I don't think it would be necessary to even do all those calculations, but it really depends on what you're doing.
If the calculations are that necessary, then calculate them, then echo them so you know what sub_str is calling. Then, adjust your calculations; when they echo correctly, there's no need to echo them anymore and your code will be working properly.
IF you type 'a' in the search, ofcourse your results won't match. If you type web at yahoo, you won't get the best results assuming you were searching for web developers in oregon.
Instead of one word, search for more than one.
Also, looking at your query, I'm guessing you have a search field for content, heading, and source-- can the user only search by one of those, not all 3?
If they could search by all 3, your final query would look something like
SELECT ID, Heading, Content FROM articles WHERE Content LIKE '%$string%' AND Source LIKE '%$string%' AND Heading LIKE '%$string%' LIMIT 0,20
and ofcourse you'd have to build that dynamically to check what fields they filled in, but if they searched for all 3, that's what your final query would look like. So lets say they filled out all 3. Your query checks for one or the other. Youd need to use AND. That may be why your search results don't match, but you didn't go into much detail on that so that's just a possibility.
Hope this helps, that was a lot of typing.
Cgraz