-7

I am running this right now:

$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
for ($i = 0; $i <= 20; $i++) {
  mysql_query("INSERT INTO my_table(user_id) values('$i')");
}

The problem is, it creates rows from 1-20. I need rows from 1500-1999 though. How would I do that?

user1227914
  • 3,446
  • 10
  • 42
  • 76
  • 4
    Have you tried changing the `0` and `20` in your `for` loop? What happened? – mario Sep 02 '15 at 15:04
  • 5
    You need to [stop using mysql_ functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Sep 02 '15 at 15:06
  • It's hard to believe that the coincidental `<= 20` (less or equal 20) in the code never struck you. – DeDee Sep 02 '15 at 15:09
  • 1
    What do you mean be needing rows 1500 to 1999? If you want entries in my_table with user_id equal to those values, just change your for loop start & end values. Also note @Machavity's comment. – PaulF Sep 02 '15 at 15:13
  • change the $i Values to $i=1500; $i<2000;$i++ – Chris West Sep 02 '15 at 15:36

2 Answers2

-1

first of all use run the following query on your table

ALTER TABLE tbl AUTO_INCREMENT = 1500;

and after that use your code

$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
for ($i = 0; $i < 500; $i++) {
  mysql_query("INSERT INTO my_table(user_id) values('$i')");
}

As you already know mysql_query() is depreciation function for new PHP version you might want to use mysqli instead.

-3

First off, don't use mysql_* functions, as Machavity has pointed out. Use mysqli_* functions.

As others have said in the comments, try changing the $i values for initial and boundary checks.

J. Han
  • 122
  • 1
  • 9