CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 (SOLVED)readmore break on my site

Print topic Send  topic

Author Message
popularanky

Posts: 53
Posted: 03/07/2012, 10:50 PM

I have a website that is use to post information like blog. All I want is a code that will help me break from the second line of word and put the readmore link to a new page that shows the full details of the post. Like on blogs
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive
View profile  Send private message
JayEdgar


Posts: 77
Posted: 03/08/2012, 8:41 AM

That is a fairly complicated request for a forum like this. This would require a page or two of custom code.
View profile  Send private message
clahti2

Posts: 107
Posted: 03/08/2012, 7:56 PM

Quote popularanky:
I have a website that is use to post information like blog. All I want is a code that will help me break from the second line of word and put the readmore link to a new page that shows the full details of the post. Like on blogs

Hmmm...this is off the top of my head, untested. How are you getting the articles? I assume you are storing them in a database. Let's say you have a table called "articles" consisting of article_id and article_text. The article_id is the primary key and article_text field is a blob or whatever.

Now let's assume you have a page articles_summary.php and articles_detail.php. Place a grid on the summary page called articles, select * from articles table. Then on the grid populate two controls, one label control for {article_text} and one link control for {article_id}. Finally in the before show event for the {article_text}:

  
$pattern = '/\n/';  
preg_match($pattern, $articles->article_text->GetValue(), $matches);  
$articles->article_text->SetValue($matches[0]);  
  
  
The above should shorten the label control to display the text up until the first line break.  The {article_id} link control should have static text "Read More..." and link to articles_detail.php passing the parameter article_id.  The detail page can then have a "record" which has a label showing the full article text. 
                   
View profile  Send private message
popularanky

Posts: 53
Posted: 03/08/2012, 10:08 PM


Quote :
Hmmm...this is off the top of my head, untested. How are you getting the articles? I assume you are storing them in a database. Let's say you have a table called "articles" consisting of article_id and article_text. The article_id is the primary key and article_text field is a blob or whatever. Now let's assume you have a page articles_summary.php and articles_detail.php. Place a grid on the summary page called articles, select * from articles table. Then on the grid populate two controls, one label control for {article_text} and one link control for {article_id}. Finally in the before show event for the {article_text}:
 $pattern = '/\n/'; preg_match($pattern, $articles->article_text->GetValue(), $matches); $articles->article_text->SetValue($matches[0]); 
  The above should shorten the label control to display the text up until the first line break.  The {article_id} link control should have static text "Read More..." and link to articles_detail.php passing the parameter article_id.  The detail page can then have a "record" which has a label showing the full article text. 
I have tried the code and it return blank. Anyway, My table is called: problem and the field is: pro_desc, also on the grid. I have problem grid and pro_desc as the display column. this is the code
$pattern = '/\n/'; preg_match($pattern, $problem->pro_desc->GetValue(), $matches); $problem->pro_desc->SetValue($matches[0]);
and nothing is displaying on pro_desc column.
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive
View profile  Send private message
popularanky

Posts: 53
Posted: 03/08/2012, 10:42 PM

Getting this error now
Quote :
Notice: Undefined offset: 0 in C:\xampp\htdocs\wimbid\Index_events.php on line 22
and line 22 is
$problem->pro_desc->SetValue($matches[0]);

_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive
View profile  Send private message
clahti2

Posts: 107
Posted: 03/10/2012, 1:18 PM

Quote popularanky:
Getting this error now
Quote :
Notice: Undefined offset: 0 in C:\xampp\htdocs\wimbid\Index_events.php on line 22
and line 22 is
$problem->pro_desc->SetValue($matches[0]);

Ok, I said my code was untested :-), try something like this:

  
$pattern = '/\n/';  
$string = $problem->pro_desc->GetValue();  
if (preg_match($pattern, $string, $matches, PREG_OFFSET_CAPTURE)) {  
  //we found a line break, get the offset  
  $offset = $matches[0][1];  
  $chopstring = substr($string,0,$offset);  
} else {  
  //no line break, so just grab the first 100 characters;  
  $chopstring = substr($string,0,100);  
}  
$problem->pro_desc->SetValue($chopstring);  

I tested this and it should work for you.
View profile  Send private message
Wreckmaster

Posts: 48
Posted: 03/10/2012, 4:54 PM

Hi clahti2 thanks for the code,
I was looking for some thing like this recently.
is there a simple piece of code which would allow me to chop at 100 characters for (sample) article-id and article-text ?

thanks again

View profile  Send private message
popularanky

Posts: 53
Posted: 03/10/2012, 9:42 PM

Hi Clahti2
I highly appreciate your support. your professional help has really help me solve the issue.

Thanks very Much. Will always remain grateful.
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive
View profile  Send private message
drLeo

Posts: 12
Posted: 03/12/2012, 4:27 AM

Quote popularanky:
Hi Clahti2
I highly appreciate your support. your professional help has really help me solve the issue.

Thanks very Much. Will always remain grateful.

Can do it with Jquery as well !
View profile  Send private message
clahti2

Posts: 107
Posted: 03/12/2012, 9:51 AM

Quote Wreckmaster:
Hi clahti2 thanks for the code,
I was looking for some thing like this recently.
is there a simple piece of code which would allow me to chop at 100 characters for (sample) article-id and article-text ?

thanks again



$chopstring = substr($string,0,100);
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.