Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2006
    Posts
    1

    Unanswered: A Question of MySQL

    hello everyone,

    i real need you help! i wanna create a table with a strict number of rows!
    i have tried option MAX_ROWS, but that is in vain. i do not know how to do it, now! Thank you!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what number?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2006
    Posts
    27
    Not sure why you'd want to do that. A DB is not supoosed to enforce something like that.

    If this is a v5, you should be able to put a trigger on it, or you could load the table and jigger the permissions so noone has insert permissions.

    To suggest a method, kinda need to know WHY you want this

    Jay Grubb
    Technical Consultant
    OpenLink Software
    Web: http://www.openlinksw.com:
    Product Weblogs:
    Virtuoso: http://www.openlinksw.com/weblogs/virtuoso
    UDA: http://www.openlinksw.com/weblogs/uda
    Universal Data Access & Virtual Database Technology Providers

  4. #4
    Join Date
    Jan 2006
    Posts
    1
    This is a piece of my old code. I used it against fake download counter.
    DB should be filled for required records quantity with blank data before using.

    CREATE TABLE Hits (
    Hit int(10) NOT NULL default '0',
    Program smallint(6) unsigned NOT NULL default '0',
    Expiration_Date int(10) NOT NULL default '0',
    PRIMARY KEY (Hit,Program),
    KEY Program (Program),
    KEY Expiration_Date (Expiration_Date)
    ) TYPE=MyISAM MIN_ROWS=100 MAX_ROWS=100 PACK_KEYS=1 ROW_FORMAT=FIXED;
    MIN_ROWS and MAX_ROWS have no sense at all. only for appearance... :-)


    PHP Code:
              if($hits_count)
              {
                
    $query='SELECT 1 FROM `Hits` WHERE `Hit`='.$user->ip.' AND `Program`='.$this->program['Program'].' LIMIT 1';
                
    $r=&$db->query(&$query);
                if(!
    $db->num_rows(&$r))
                {
                  
    $query='SELECT `Hit`,`Program` FROM `Hits` ORDER BY `Expiration_Date` LIMIT 1';
                  
    $r=&$db->query(&$query);
                  list(
    $hit,$program)=$db->fetch_row(&$r);
                  
    $db->free_result(&$r);

                  
    $query='UPDATE `Hits` SET `Hit`='.$user->ip.',`Program`='.$this->program['Program'].',`Expiration_Date`='.time().' WHERE `Hit`='.$hit.' AND `Program`='.$program.' LIMIT 1';
                  
    $db->query(&$query);
                  
    $query='UPDATE `Programs` SET `Real_Hits_Count`=`Real_Hits_Count`+1 WHERE `Program`='.$this->program['Program'].' LIMIT 1';
                  
    $db->query(&$query);
                }
              } 
    ...there I'm using 'update' instead 'insert'....


    Regards

Posting Permissions

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