Current location: Hot Scripts Forums » Programming Languages » PHP » How to display from $a line to $z line ?


How to display from $a line to $z line ?

Reply
  #1 (permalink)  
Old 12-20-04, 02:26 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
How to display from $a line to $z line ?

I query data from db_table_name from mysql server
---------------------------
PHP Code:

select  table_name  from  testdb  where  id 100  

and I want to display data only start from line 2 to line 5


line 1
line 2 start to display from this line
line 3
line 4
line 5 end of display
line 6
line 7

----------
can anyone show me the php code for display just start from line2 -line5

any suggestion ?

Thank in advance
Reply With Quote
  #2 (permalink)  
Old 12-20-04, 02:29 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Hi....
LIMIT x,x
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #3 (permalink)  
Old 12-20-04, 03:01 PM
Vulture Vulture is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Scotland, UK
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

SELECT FROM `table_name`  LIMIT 2
Something like that? Returns 4 entries from record #2
Reply With Quote
  #4 (permalink)  
Old 12-20-04, 03:28 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
not what is meant

I mean if I query just 1 row and display 1 row only
and data in that row has many line inside

for example

my sql return

ID= 100

inside ID 100 has texts content about 7 lines


line 1
line 2 start to display from this line
line 3
line 4
line 5 end of display
line 6
line 7


data from mysql has 7 line but i want to display from line 2 - 5 ?
and how to write php to display from line 2 - 5 ?
Reply With Quote
  #5 (permalink)  
Old 12-21-04, 11:24 PM
xtremenw xtremenw is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Tacoma, WA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by websnow
not what is meant

I mean if I query just 1 row and display 1 row only
and data in that row has many line inside

for example

my sql return

ID= 100

inside ID 100 has texts content about 7 lines


line 1
line 2 start to display from this line
line 3
line 4
line 5 end of display
line 6
line 7

data from mysql has 7 line but i want to display from line 2 - 5 ?
and how to write php to display from line 2 - 5 ?
So you are saying that the column you want to parse data out of is a 'TEXT' column type? That is a little more complicated... You can try to use:

Code:
preg_replace(/^((\w+)+(\s|\n)?$/, $found).
just remember that $found will be an array not not all of the text.. This will only print, none blank lines. so, line 3 & 4 will not be printed... If that even works.
Reply With Quote
  #6 (permalink)  
Old 12-22-04, 01:56 AM
irfanbaba's Avatar
irfanbaba irfanbaba is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Karachi, Pakistan
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Hi,

Use following Code
PHP Code:



<?php
// =====================================================
// FILE: Paging.php
//
// =====================================================
// Description: This class handles the paging to be print to the browser.
//
// This is distribute as is. Free of use and free to do anything you want.
// 
// PLEASE REPORT ANY BUG TO ME BY EMAIL :)
//
// =========================
// Programmer:      Pierre-Yves Lemaire
//                                            [email]py@ottawa.com[/email]
// =========================
// Date:            2001-03-25
// Version: 1.0
// =====================================================
class Paging {
    var 
$int_num_result;                                            // Number of result to show per page
    
var $int_nbr_row;                                                    // Total number of items (generally a sql count from db)
    
var $int_cur_position;                                        // Current position in recordset
    
var $str_table_bgcolor;                                    // Color of the html table contour, default to black
    
var $str_table_width;                                            // Width of the HTML table, default to 400 pixel
    
var $img_source_next = \"<img src=\\\"paging_r_arrow.gif\\\" width=\\\"7\\\" height=\\\"9\\\" border=0 alt=\\\"Previous\\\">\"; 
    var 
$img_source_previous = \"<img src=\\\"paging_l_arrow.gif\\\" width=\\\"7\\\" height=\\\"9\\\" border=0 alt=\\\"Next\\\">\";

    // ------------------------------------------------------------------------------------------ Constructor
    //
    function Paging( 
$int_nbr_row$int_cur_position$int_num_result$str_table_bgcolor = \"#000000\", $str_table_width = 400 ){
        
$this->int_nbr_row = $int_nbr_row;
        
$this->int_num_result = $int_num_result;
        
$this->int_cur_position = $int_cur_position;
        
$this->str_table_bgcolor = $str_table_bgcolor;
        
$this->str_table_width = $str_table_width;
    } // End constructor

    // ------------------------------------------------------------------------------------------ getNumberOfPage()
    // This function returns the total number of page to display.
    function getNumberOfPage(){
        
$int_nbr_page = $this->int_nbr_row / $this->int_num_result;
        if( 
$int_nbr_page % 2 != 0 ){
            
$int_nbr_page += 1;
        }
        return 
$int_nbr_page;
    } // end function
    
    // ------------------------------------------------------------------------------------------ getCurrentPage()
    // This function returns the current page number.
    function getCurrentPage(){
        
$int_cur_page = ( $this->int_cur_position * $this->getNumberOfPage() ) / $this->int_nbr_row;
        return number_format( 
$int_cur_page, 0 );
    } // end function

    // --------------------------------------------------------------------------------------------------- openTable()
    // This function simply opens the HTML table.
    function openTable(){
        
$ret = \"<table cellspacing=0 cellpadding=1 border=0 width=\\\"\". $this->str_table_width .\"\\\">\\n<tr>\\n<td align=center bgcolor=\\\"\". $this->str_table_bgcolor .\"\\\">\"
        .\"<table cellspacing=0 cellpadding=1 border=0 width=\\\"100%\\\">\\n<tr bgcolor=\\\"#FFFFFF\\\">\\n\";
        return 
$ret;
    } // end function

    // --------------------------------------------------------------------------------------------------- closeTable()
    // This function simply close the HTML table.
    function closeTable(){
        
$ret = \"</tr></table></td></tr></table>\";
        return 
$ret;
    } // end function

    // -------------------------------------------------------------------------------------------------- printPaging()
    // This function print the paging to the screen. 
    function printPaging(){
        global 
$PHP_SELF;

        // Open the html table
        print 
$this->openTable();

        print \"<td align=center bgcolor=\\\"#efefef\\\" valign=top>· File \". ( 
$this->int_cur_position + 1 );
        print \" - \";
        if( 
$this->int_cur_position + $this->int_num_result >= $this->int_nbr_row ){
            print 
$this->int_nbr_row;
        }else{ print ( 
$this->int_cur_position + $this->int_num_result ); }
        print  \" of \". 
$this->int_nbr_row .\"</td>\\n\";
        
        print \"<td align=center valign=top>\\n\";

        // Previous link here
        if ( 
$this->int_cur_position != 0 ){
            print \"<a href=\\\"
$PHP_SELF?int_cur_position=\". ( $this->int_cur_position - $this->int_num_result ).\"\\\">\\n\";
            print 
$this->img_source_previous .\"</a>\\n\";
            print \"&nbsp;&nbsp;&nbsp;\\n\";
        }            
        // Printing all pages as a link
        for( 
$i=0; $i<$this->getNumberOfPage(); $i++ ){
            // On current page, do not print the link
            if( 
$i == $this->getCurrentPage() ){
                print 
$i+1;
            }else{
                
$int_new_position = ( $i * $this->int_num_result );
                print \" <a href=\\\"\". 
$PHP_SELF .\"?int_cur_position=$int_new_position\\\">\". ($i+1) .\"</a> \\n\";
            }
        }
        print \"&nbsp;&nbsp;&nbsp;\\n\";

        // next link here
        if( ( 
$this->int_nbr_row - $this->int_cur_position ) > $this->int_num_result ){
            
$int_new_position = $this->int_cur_position + $this->int_num_result;    
            print \"<a href=\\\"
$PHP_SELF?int_cur_position=$int_new_position\\\">\\n\";
            print 
$this->img_source_next .\"</a></td>\\n\";
        }

            // close html table
            print 
$this->closeTable();
    } // End function printPaging

}; // End Class

// ==============================================================
// Exemple Usage
if( !isset( 
$int_cur_position ) ){
    
$int_cur_position = 0;
}

// Usually, the 2 queries to the database would look like this:
// Get the total number of result from db
// 
$sql1 = \"Select count( field_primary_key ) as nb FROM table\";

// Select only fields needed according to paging
// 
$sql2 = \"Select * FROM table ORDER BY row \"
// .\"LIMIT 
$int_cur_position$int_num_result\";

$result_from_sql1 = 100;        // exemple with a hundred fields

$p = new Paging( $result_from_sql1$int_cur_position, 10 ,\"#336699\", \"400\" );
$p->printPaging();

?>
Hope this may help
__________________
Web Programmer
web: http://www.netxs.com.pk
email: irfanmail@gmail.com
msn : irfanbaba@hotmail.com
Reply With Quote
  #7 (permalink)  
Old 12-22-04, 05:34 PM
websnow websnow is offline
Newbie Coder
 
Join Date: Jun 2003
Location: London
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very much

I will try it
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirection back to a page from form submit DAL Perl 11 03-21-05 02:45 PM
I most definately suggest DevelopingCentral.com For Any Website Design/Development! Salty777 General Advertisements 2 10-01-04 04:27 AM
asp-iis-Server error nsuresh_rasr ASP.NET 3 02-08-04 12:47 AM


All times are GMT -5. The time now is 05:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.