Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to do multiple querys in one?

    Hi I have an install script that does multiple queries but when I tried to make it into one query variable it didnt work. Like this
    PHP Code:
    <?php            $query="CREATE TABLE categories (
                    id int(7) NOT NULL auto_increment,
                    category varchar(50) NOT NULL default '',
                      PRIMARY KEY  (id)
                    ) TYPE=MyISAM AUTO_INCREMENT=16 ;
                    INSERT INTO categories VALUES (1, 'Action');
                    INSERT INTO categories VALUES (2, 'Adventure');
                    INSERT INTO categories VALUES (3, 'Arcade');
                    INSERT INTO categories VALUES (4, 'Driving');
                    INSERT INTO categories VALUES (5, 'Multiplayer');
                    INSERT INTO categories VALUES (6, 'Puzzle');
                    INSERT INTO categories VALUES (7, 'Cards/Casino');
                    INSERT INTO categories VALUES (8, 'Sports');
                    INSERT INTO categories VALUES (9, 'Shooting');
                    INSERT INTO categories VALUES (10, 'Other');
                    CREATE TABLE games (
                      id int(7) NOT NULL auto_increment,
                      type varchar(6) NOT NULL default '',
                      name varchar(200) NOT NULL default '',
                      category varchar(200) NOT NULL default '',
                      filetype varchar(9) NOT NULL default '',
                      file text NOT NULL,
                      other text NOT NULL,
                      directions text NOT NULL,
                      link text NOT NULL,
                      PRIMARY KEY  (id)
                    ) TYPE=MyISAM AUTO_INCREMENT=60 ;"
    ;
    ?>
    Other stuff is there but how can I make that all one mysql query?

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    quite simply, you cant.. mysql_query() can only do one query at a time.

    You could put your queries into an array, and do them in a loop:

    PHP Code:
    $sql[] = 'QUERY 1';
    $sql[] = 'QUERY 2';
    $sql[] = 'QUERY 3';

    foreach(
    $sql as $query){
       
    mysql_query($sql);



  •  

    Posting Permissions

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