wargolchaos Posted August 26, 2009 Share Posted August 26, 2009 In case the topic didn't say it all I am looking for a way to limit the amount of text I pull from the database to display on my news page. The goal is to display a small peice of the news and then add a read more link which will go to another page and load up the article. The read more I can handle but limiting the text for the front page has me stumped at the moment. Heres my MySQL code. $maxRows_rsNews = 10; $pageNum_rsNews = 0; if (isset($_GET['pageNum_rsNews'])) { $pageNum_rsNews = $_GET['pageNum_rsNews']; } $startRow_rsNews = $pageNum_rsNews * $maxRows_rsNews; mysql_select_db($database_conndb, $conndb); $query_rsNews = "SELECT * FROM tbl_news ORDER BY id DESC"; $query_limit_rsNews = sprintf("%s LIMIT %d, %d", $query_rsNews, $startRow_rsNews, $maxRows_rsNews); $rsNews = mysql_query($query_limit_rsNews, $conndb) or die(mysql_error()); $row_rsNews = mysql_fetch_assoc($rsNews); if (isset($_GET['totalRows_rsNews'])) { $totalRows_rsNews = $_GET['totalRows_rsNews']; } else { $all_rsNews = mysql_query($query_rsNews); $totalRows_rsNews = mysql_num_rows($all_rsNews); } $totalPages_rsNews = ceil($totalRows_rsNews/$maxRows_rsNews)-1; Thanks for any help in advance. Quote Link to comment https://forums.phpfreaks.com/topic/171912-limiting-mysql-field-words-for-news-topic/ Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 $length = 180;//characters long $excerpt = $string; if ($length + 10 < strlen($string)) { $pos = strpos($string, ' ', $length); $excerpt = substr($string, 0, $pos >= $length ? $pos : $length); } Quote Link to comment https://forums.phpfreaks.com/topic/171912-limiting-mysql-field-words-for-news-topic/#findComment-906490 Share on other sites More sharing options...
wargolchaos Posted August 27, 2009 Author Share Posted August 27, 2009 How can I make this work with what I have set up? Do I tie $excerpt to my query statement some how? Quote Link to comment https://forums.phpfreaks.com/topic/171912-limiting-mysql-field-words-for-news-topic/#findComment-907178 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 $length = 180;//characters long $excerpt = $string; if ($length + 10 < strlen($string)) { $pos = strpos($string, ' ', $length); $excerpt = substr($string, 0, $pos >= $length ? $pos : $length); } Most people on these forums provide solutions and integrate them directly into the code the OP (you) provided on which they just copy-paste the added part into their existing code. I don't do that because you don't learn anything from it and the next time you have the same problem you will be asking for it again on this or some other forum because what you copy-pasted last time does not entirely fit into the new project and thus needs to be modified. And modifying something you didn't knew in the first place.. So I'm sorry but "How can I make this work with what I have set up?" will be your end of the bargain. Quote Link to comment https://forums.phpfreaks.com/topic/171912-limiting-mysql-field-words-for-news-topic/#findComment-907347 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.