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 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Basic Script with MySQL

    Can someone give me some basic script that uses MySQL and PHP functions and variables please? I just want to use it to learn how to code, I'm a visual learner so I think it'll help. Thanks.

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a basic script to find a record with a particular number:

    PHP Code:
    $ladderQuery "SELECT * FROM ladders WHERE num = ".$l;
    $ladderInfo mysql_Query($ladderQuery);
    $ladder mysql_Fetch_Array($ladderInfo); 
    If you ask for more specific things I can probably be more helpful.

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm... How about something that you click on a link and Number A (stored in the MySQL Database) goes up a random number between 8 and 10.

  • #4
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Quote Originally Posted by QwertyKeyboard
    Hmm... How about something that you click on a link and Number A (stored in the MySQL Database) goes up a random number between 8 and 10.
    PHP Code:
    <?php
    if (isset($_POST['update']))
    {
        
    mysql_connect('localhost''root''');
        
    mysql_select_db('somedb');
        
    mysql_query('CREATE TABLE IF NOT EXISTS `sometable` (
            `id` INT NOT NULL AUTO_INCREMENT ,
            `somefield` INT NOT NULL ,
            PRIMARY KEY ( `id` )
            ) TYPE = innodb;'
    );
        
    mysql_query('INSERT INTO `sometable`(`somefield`, `id`) 
            VALUES (' 
    mt_rand(810) . ', 1) 
            ON DUPLICATE KEY UPDATE `somefield` = `somefield` + ' 
    mt_rand(8,10));
        
    $q mysql_query('SELECT `somefield` 
            FROM `sometable` 
            WHERE `id` = 1 
            LIMIT 1'
    );
        
    $r mysql_fetch_assoc($q);
        
    print_r($r);
    }

    ?>
    <html>
    <body>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <input name="update" type="submit" value="do the thing" />
    </form>
    </body>
    </html>
    Last edited by ralph l mayo; 02-12-2006 at 07:43 AM.

  • #5
    New Coder
    Join Date
    Jan 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, though what do I fill in to the "sometable" thing?

  • #6
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Nothing, the only thing that needs to change is the connection username and password if you have something other than the default root/blank and the database name. MySQL should install with a database named 'mysql' if you don't know how to create your own.


  •  

    Posting Permissions

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