SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    New Line is not taking when it show the article from database

    Hi all,
    In admin panel,
    I have A textbox where i put a data like
    Code:
    We need to do a different page ordina , similar to the published one.
    Image + Flash text same as BODYSLIM page.
    
    Translate: “1 Confezione con 30 Cerotti” with “60 Capsule = 30 Giorni di Trattamento per perdere fino a 5 Kg - Euro 49 + 6€ spese di spedizione contrassegno
    
    Translate :” Offerta 3x2: 3 Confezioni 
    (90 giorni di trattamento) 
    ad Euro 98 + 6€ spese di spedizione”
    
    With: “Offerta 3x2: 3 Confezioni 
    90 giorni di trattamento per perdere fino a 15 Kg
    ad Euro 98 + 6€ spese di spedizione
    
    
    All the rest will be the same.
    Obviously on DATABASE we should be able to choose which product/orders to see/print (i.e. 1…print all CEROTTO Orders  or PRINT ALL BODYSLIM ORDERS)
    But in User section the data is shows in this way
    Code:
    We need to do a different page ordina similar to the published one Image Flash text same as BODYSLIM page Translate Confezione con Cerotti with Capsule Giorni di Trattamento per perdere fino a Kg Euro € spese di spedizione contrassegno Translate Offerta x Confezioni giorni di trattamento ad Euro € spese di spedizione With Offerta x Confezioni giorni di trattamento per perdere fino a Kg ad Euro € spese di spedizione All the rest will be the same Obviously on DATABASE we should be able to choose which product orders to see print i e print all CEROTTO Orders or PRINT ALL BODYSLIM ORDERS
    In that page My PHP code is
    Code:
    $sql="select * from tbl_article where aid=".$_REQUEST['id'];
      $query=$db->select_data($sql);
      $result=$db->get_row($query);
      $content=$result['acontent'];
      $str=str_word_count($content,1);
      $total_count=count($str);
      $strin="";
      $k=(empty($_REQUEST['lax'])) ? '0' : $_REQUEST['lax'];
      $limit=$k+400;
      $limitup=$limit+1;
    	  for($i=$k;$i<=$limit;$i++)
    	  {	
    	  $strin=$strin." ".$str[$i];
    	  }
    	  $smarty->assign("article",$strin);
    Where has gone new line when i use str_word_count
    Is there any way to fix this issue?
    -::Ujjwal::-
    Visit My Site

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry SPikez,
    Code:
    $sql="select * from tbl_article where aid=".$_REQUEST['id'];
      $query=$db->select_data($sql);
      $result=$db->get_row($query);
      $content=$result['acontent'];
      $str=str_word_count($content,1);
      $total_count=count($str);
      $strin="";
      $k=(empty($_REQUEST['lax'])) ? '0' : $_REQUEST['lax'];
      $limit=$k+400;
      $limitup=$limit+1;
    	  for($i=$k;$i<=$limit;$i++)
    	  {	
    	  $strin=$strin." ".nl2br($str[$i]);
    	  }
    	  $smarty->assign("article",$strin);
    But it still show the data in one by one not taking new line.
    -::Ujjwal::-
    Visit My Site

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Use the nl2br when the data is UTPUT onto the page ie: it's final destination.
    I dont use Smarty but from the looks of it, this line:
    PHP Code:
    $smarty->assign("article",$strin); 
    could be changed to:
    PHP Code:
    $smarty->assign("article",nl2br($strin)); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry SPike,
    It is not working I think str_word_count would be the main Problem.
    -::Ujjwal::-
    Visit My Site

  6. #6
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and In Mysql Db
    The database value is
    Code:
    We need to do a different page ordina , similar to the published one.
    Image + Flash text same as BODYSLIM page.
    
    Translate: “1 Confezione con 30 Cerotti” with “60 Capsule = 30 Giorni di Trattamento per perdere fino a 5 Kg - Euro 49 + 6€ spese di spedizione contrassegno
    
    Translate :” Offerta 3x2: 3 Confezioni 
    (90 giorni di trattamento) 
    ad Euro 98 + 6€ spese di spedizione”
    
    With: “Offerta 3x2: 3 Confezioni 
    90 giorni di trattamento per perdere fino a 15 Kg
    ad Euro 98 + 6€ spese di spedizione
    
    
    All the rest will be the same.
    Obviously on DATABASE we should be able to choose which product/orders to see/print (i.e. 1…print all CEROTTO Orders  or PRINT ALL BODYSLIM ORDERS)
    -::Ujjwal::-
    Visit My Site

  7. #7
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump
    -::Ujjwal::-
    Visit My Site

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Morning ujjwal, my apologies for not getting back yesterday.

    Dont know why I didn't think about it but str_word_count returns an array of the words and so looses all formating which is why it wont display as you want it.

    Looking through your code it seems you are trying to limit the number of words displayed.....?

    If so you can either write a function using substr() in PHP or SUBSTRING() in mysql.

    so the php function would be something like:
    PHP Code:
    function snippet($text,$length=64,$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;

    and the mysql function:
    Code:
    select SUBSTRING(fieldname, 0, 400) from tbl_article where aid=".$_REQUEST['id'];
    Something along those lines. and THEN use nl2br when printing it out on the page.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes SPikez ,
    In kolkata,Good Afternoon SPikeZ.
    Now you are right.
    I want to display 400 words of article in one page.(and works like Pagination)
    If i use substr then it might be break in such a way which is not readable.
    like(the sentence is:"I like you" and might be it cut and then show "I li" in one page...
    So i use str_word_count to avoid this situations.
    Thanks
    for your explanation.
    I will do it and then informed it 2 you.
    Last edited by ujjwal; Apr 26, 2007 at 02:21. Reason: To more elaborate
    -::Ujjwal::-
    Visit My Site

  10. #10
    SitePoint Member subhasishweb's Avatar
    Join Date
    Mar 2006
    Location
    West Bengal, India
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Ujjwal,

    Subhasish here.... i think nl2br function is the correct function to you and you did not use it properly.

    Further detail, please call me on my mobile: +91 9831581556.
    Thanks & Regards,
    ---
    Subhasish Nag
    http://www.subhasish.net/

  11. #11
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if all else fails!

    PHP Code:
    $text str_replace(array("\r\n""\r""\n"), ' <br />'$text); 

  12. #12
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Spike Z.
    Code:
    function snippet($text,$length=64,$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; 
    }
    It works but i want to link instead of tail($tail="...") in such a way that next content of that article should display (like pagination does)

    Will you help me??
    -::Ujjwal::-
    Visit My Site

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    OK then,
    in the function it expects parameters ($text,$length=64,$tail="...)
    so lets add another one: $start
    and change another: $tail= will go completely

    Then you have to tell the function where you are in the article and which part to display next. In this case the second 100 characters.....

    PHP Code:
    <?php

    $text 
    "Yes SPikez ,
    In kolkata,Good Afternoon SPikeZ.
    Now you are right.
    I want to display 400 words of article in one page.(and works like Pagination)
    If i use substr then it might be break in such a way which is not readable.
    like(the sentence is:I like you and might be it cut and then show I li in one page...
    So i use str_word_count to avoid this situations.
    Thanks
    for your explanation.
    I will do it and then informed it 2 you."
    ;

    function 
    snippet($text,$length=30,$start) { 
         
        
    $start = isset($_GET['start']) ? $_GET['start']+$length 0;

        
    $text trim($text); 
        
    $txtl strlen($text); 
        if(
    $txtl $length) { 
            for(
    $i=1;$text[$length-$i]!=" ";$i++) { 
                if(
    $i == $length) { 
                    return 
    substr($text,$start,$length) . '<a href="?start='$start.'">More</a>'
                } 
            } 
            
    $text substr($text,$start,$length-$i+1) . '<a href="?start='$start.'">More</a>'
        } 
        return 
    $text
    }

    echo 
    snippet(nl2br($text), 100,'');

    ?>
    See if that works for you
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a Lot SPike Z.
    Y0u r a genious.
    -::Ujjwal::-
    Visit My Site

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    No worries ujjwal, glad I could help
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •