Hello All.
I'm trying to loop the following statement with PHPmyAdmin in order to add 1000 entries with the variable "i" incremented for each entry. (data and ip can be static)

INSERT INTO 'TABLE'('id', 'data', 'ip') VALUES ([i], [06/03/2016],[192.168.0.1])

It's been 20 years since I've done any coding with loops. Can anyone help me?

Recommended Answers

All 3 Replies

CREATE TABLE `test_table`(
    `id` INT NOT NULL AUTO_INCREMENT,
    `data` DATE,
    `ip` VARCHAR(30),
    PRIMARY KEY (`id`)
);

DELIMITER $$
DROP PROCEDURE IF EXISTS insert_data; $$
CREATE PROCEDURE insert_data(IN p_cur INT, IN p_max INT)
BEGIN
    TRUNCATE TABLE `test_table`;
    START TRANSACTION;
    WHILE p_cur <= p_max do
        INSERT INTO `test_table`(`id`, `data`,`ip`) VALUES (p_cur, NOW(), '192.168.0.1');
        SET p_cur = p_cur + 1;
    END WHILE;
    COMMIT;
END; $$
DELIMITER ;
CALL insert_data(1,1000);

Thanks alot! With some slight modification, this works PERFECTLY!

Great Community!

If problem is solved then mark thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.