Re: Only a section from the database result
| From: | dpgirago at mdanderson dot org | Date: | Tue, 18 Jul 2006 17:57:48 +0000 |
| Subject: | Re: Only a section from the database result | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-42226@lists.php.net to get a copy of this message | ||
> I have articles in a MySQL database and I want creating a fast brows
> where people can read the beginning of the articles and select
> the ones they want to read.
>
> How do I only display the first say 50 chars of a 5000 char article?
>
> $count = 1;
> while(($row = mysql_fetch_array($News)) or ($count < 15)){
> if(isset($row['threadid'])){
> echo "<b><a href='./showpost.php?t=" . $row['threadid'] .
> "'>" .
> $row['title']. "</a></b><br \>";
> echo " " . $row['dateline'] . " --
> by: " . $row
> ['postusername'] . "<br \>";
> echo " Views: " . $row['views'] . " -
> Comments:
> " . $row['replycount'] . "<br \><br \>";
> echo "<p>" . $row['pagetext'] . "</p>"; //This is
> the variable I
> only want the fist 50 chars
> }
> $count++;
> }
One possible solution is to select from the database only the first 50
characters for display in the initial page: "SELECT left(FieldName, 50)
FROM tablename";
Once a user has chosen the articles they would like to read, run another
query and select the entire content field.
David