DarkJamie Posted February 16, 2010 Share Posted February 16, 2010 I am having trouble finding info on how to display a partial result from my sql query. I know what I'd like to do is really simple, but my search always results in how to paginate my query results rather than display the partial data with more link. I'd like it to display like this: Story Title - Date Entered words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here words go here ...more I can display my results just fine, I would just like to place the partial story on my main page like this. If anyone can point me in the right direction so I can read up on it, I'd be greatful. Quote Link to comment https://forums.phpfreaks.com/topic/192315-help-displaying-partial-results-with-more-link/ Share on other sites More sharing options...
dbradbury Posted February 16, 2010 Share Posted February 16, 2010 im not sure how this would be done exactly, out of my depth in php, lol, as id like to know this aswell but its gonna be something like limiting the text variable to a certain amount of words or something, then making a link, that take you to the correct place sorry i cant be of any more help. Quote Link to comment https://forums.phpfreaks.com/topic/192315-help-displaying-partial-results-with-more-link/#findComment-1013428 Share on other sites More sharing options...
premiso Posted February 16, 2010 Share Posted February 16, 2010 substr would be the function I would start to look at. (I would also look at the user comments on that page) Quote Link to comment https://forums.phpfreaks.com/topic/192315-help-displaying-partial-results-with-more-link/#findComment-1013430 Share on other sites More sharing options...
DarkJamie Posted February 17, 2010 Author Share Posted February 17, 2010 Thank you Premiso. I'm reading up on that now. Quote Link to comment https://forums.phpfreaks.com/topic/192315-help-displaying-partial-results-with-more-link/#findComment-1013500 Share on other sites More sharing options...
Grayda Posted February 17, 2010 Share Posted February 17, 2010 Why not try this?: SELECT LEFT(title, 160) FROM myTable WHERE title = "SomeTitle" That will get the first 160 characters from the 'title' column in 'myTable'. If you want the last 160, change left to right. You could even combine them so you can get 80 characters from the left and 80 from the right. Quote Link to comment https://forums.phpfreaks.com/topic/192315-help-displaying-partial-results-with-more-link/#findComment-1013553 Share on other sites More sharing options...
DarkJamie Posted February 17, 2010 Author Share Posted February 17, 2010 I've solved the problem. For anyone looking to display "x" amount of characters of a query result, the following function works perfectly: Define your $text variable from your query results (in my case "content") $text=$row['content']; Set the number of characters by defining $length and the trailing characters (...) by defining $tail function snippet($text,$length=164,$tail="...") { $text = trim($text); $txtl = strlen($text); if($txtl > $length) { for($i=1;$text[$length-$i]!=" ";$i++) { if($i == $length) { return substr($text,0,$length) . $tail; } } $text = substr($text,0,$length-$i+1) . $tail; } return $text; } then to print the limited result: echo snippet($text); Quote Link to comment https://forums.phpfreaks.com/topic/192315-help-displaying-partial-results-with-more-link/#findComment-1013590 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.