Activity Stream
48,167 MEMBERS
6602 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 42
  1.     
    #31
    Member
    Website's:
    imdber.org justpaste.me
    ^What language is that, java?

  2.     
    #32
    Respected Member
    Website's:
    DL4Everything.com Soft2050.in
    C#

  3.     
    #33
    Member
    Website's:
    mytinydick.com
    Code: 
    <b>hello world</b>
    I made bold text

    Bad bitch in my chevy.

  4.   Sponsored Links

  5.     
    #34
    Respected Developer
    Website's:
    X4B.org
    Quote Originally Posted by JmZ View Post
    Seems interesting. Ideally though you should keep row counters in another table and update them on insertion of a new row. This way you simply select the appropriate counter rather than counting the rows each time (e.g. rowcounts(int key, int counter)).

    My snippet, isn't a snippet today.
    Rather a suggested logic you should implement.

    Basically pagination. You reminded me of it just now.

    Many, many people do the following:
    - Select the rows (limited to rows_per_page from the page offset)
    - Select count(*) of same query without a limit
    - Use the count to display how many pages of results there are and to know how many page links to show

    What people should do is this:
    - Select the rows (limited to rows_per_page+1 from the page offset)
    - If your result set is of size rows_per_page+1, display a 'next page' link and remove the last row from the set
    - If your result set is of a size less than rows_per_page+1, show no 'next page' link
    - If your current page is > 1, show a 'previous page' link

    This way you never select a count(), you only use one query.
    Ive seen that used before, its very efficient if you only need next & previous navigation. And great for innodb where count()'s are expensive.

  6.     
    #35
    Trusted Webmaster
    Website's:
    KWWHunction.com
    Hope to see this thread continue its life span

  7.     
    #36
    Respected Developer
    Website's:
    X4B.org
    Your wish is my command, nothing special just a excerpt of a rarely used but useful pattern

    PHP Code: 
    abstract class System {
            abstract function 
    toUrl();
        abstract function 
    onReceived(Transaction $p);
        abstract function 
    onSuccess();

    // [...]
    }
    class 
    UpstreamSystem extends System {
        private 
    $u;
        function 
    __construct($u){
            
    $this->$u;
        }
        
        function 
    toUrl(){
            return 
    $this->u->toUrl();
        }
        function 
    onReceived(Transaction $p){
            return 
    $this->u->onReceived($p);
        }
        function 
    onSuccess(){
            return 
    $this->u->onSuccess();
        } 
    Used to extend a class out of scope, usefull for callbacks etc.

  8.     
    #37
    Member
    PHP Code: 
    <?php

    class Database
    {
        var 
    $con;
        var 
    $sel;
        var 
    $res;
        var 
    $assoc;
        var 
    $escape;
        var 
    $array;
        var 
    $row;

        function 
    connect()
        {
            
    $this->con mysql_connect("localhost""host""") or die(mysql_error());
            
    $this->sel mysql_select_db("test") or die(mysql_error());
        }

        function 
    close()
        {
            if (isset(
    $this->connect)) {
                
    mysql_close($this->connect());
                unset(
    $this->connect);
            }
        }

        function 
    query($sql)
        {
            
    $this->res mysql_query($sql) or die(mysql_error());
            return 
    $this;
        }

        function 
    fetch($type)
        {
            switch (
    $type) {
                case 
    1:
                    
    $this->assoc mysql_fetch_assoc($this->res);
                    return 
    $this;
                    break;
                case 
    2:
                    
    $this->array mysql_fetch_array($this->res);
                    return 
    $this;
                    break;
                case 
    3:
                    
    $this->row mysql_fetch_row($this->res);
                    return 
    $this;
                    break;
            }
        }

        function 
    escape($escape)
        {
            
    $this->escape mysql_real_escape_string($escape);
            return 
    $this->escape;
        }


        function 
    get($num$col)
        {
            switch (
    $num) {
                case 
    1:
                    return (
    $this->assoc[$col]);
                    break;
                case 
    2:
                    return (
    $this->array[$col]);
                    break;
                case 
    3:
                    return (
    $this->row[$col]);
                    break;
            }
        }

    }
    //initiate the database class
    $database = new Database();
    //connect to the database
    $database->connect();
    //run a query
    $database->query("SELECT * FROM table");
    //runs, chooses the type of query, and what collumn
    $database->query()->fetch(1)->get(1,'username');
    //close the database
    $database->close();
    ?>

  9.     
    #38
    Member
    Website's:
    tehMoviez.com 0Senes.com GeekFaceGames.com
    an abstract class i use to fill in objects properties from an array
    PHP Code: 
    abstract class AbstractModel
    {
        public function 
    fromArray(array $data) {
            foreach (
    $data as $key => $value) {
                if (
    property_exists($this$key)) {
                    
    $this->{$key} = $value;
                }
            }
        }


  10.     
    #39
    Member
    Website's:
    imdber.org justpaste.me
    Quote Originally Posted by JmZ View Post
    Seems interesting. Ideally though you should keep row counters in another table and update them on insertion of a new row. This way you simply select the appropriate counter rather than counting the rows each time (e.g. rowcounts(int key, int counter)).

    My snippet, isn't a snippet today.
    Rather a suggested logic you should implement.

    Basically pagination. You reminded me of it just now.

    Many, many people do the following:
    - Select the rows (limited to rows_per_page from the page offset)
    - Select count(*) of same query without a limit
    - Use the count to display how many pages of results there are and to know how many page links to show

    What people should do is this:
    - Select the rows (limited to rows_per_page+1 from the page offset)
    - If your result set is of size rows_per_page+1, display a 'next page' link and remove the last row from the set
    - If your result set is of a size less than rows_per_page+1, show no 'next page' link
    - If your current page is > 1, show a 'previous page' link

    This way you never select a count(), you only use one query.
    Pagination, you reminded me, oh, headache, I hate pagination. Thanks.

  11.     
    #40
    Member
    PHP Code: 
    <?php echo '<p>Hello KWWHunction, My Name is MrOSX & I am a PHP Virgin</p>'?>

Page 4 of 5 FirstFirst ... 2345 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Plz Help To Add A Php Snippet Into My DLE Index !
    By JoomlaZ in forum Web Development Area
    Replies: 0
    Last Post: 7th Jul 2011, 01:18 PM
  2. [C#] Tiny Web Server (snippet)
    By Hyperz in forum Web Development Area
    Replies: 6
    Last Post: 24th Jun 2010, 01:19 PM
  3. Image Upload in php. Code snippet #2
    By SplitIce in forum Tutorials and Guides
    Replies: 5
    Last Post: 31st Oct 2009, 07:40 AM
  4. See real OOP (Snippet from Litewarez V2) Webmasters CP
    By litewarez in forum Tutorials and Guides
    Replies: 21
    Last Post: 19th Sep 2009, 03:59 PM
  5. A Snippet from my latest project
    By litewarez in forum Tutorials and Guides
    Replies: 19
    Last Post: 21st Jun 2009, 05:17 PM

Tags for this Thread

BE SOCIAL