Jump to content

Recommended Posts

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.

 

 

$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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.