Jump to content

Recommended Posts

I have 17659 entries that are all the same. There are only two fields in the mysql databse Products_id witch auto increments and categories_id witch is an int 10.

 

This source code throws no errors.

 

<?php
error_reporting(E_ALL);
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
	die('Connection Error:' . mysql_error());
}
	mysql_select_db('catgories', $con);
	$result = mysql_query("SELECT * FROM categories");
	$query = "INSERT INTO categories ('products_id', 'categories_id') VALUES ('', '18')";
	$i = 1;

	while ($i <= 17659) {
		mysql_query($query);
		$i++;
	}
?>

Good for you... are you trying to say that it's not working?

 

If products_id is auto increment and caegories_id is int as you say then you could try this...

 

$query = "INSERT INTO categories ('categories_id') VALUES (18)";

Omit the products_id it's not required on an auto increment field and some versions of MySQL do not like recieving a blank string as a value for auto increment fields. I also removed the single quotes from around categories_id since it is an integer not a string.

I'm confused. 

Are you wanting to put 1-17659 for each categoryid pulled from the database?

 

something like this

productid    categoryid

1                  1

2                  1

3                  1

..to 17659

1                  2

2                  2

3                  2

..to 17659

 

 

Good for you... are you trying to say that it's not working?

 

If products_id is auto increment and caegories_id is int as you say then you could try this...

 

$query = "INSERT INTO categories ('categories_id') VALUES (18)";

Omit the products_id it's not required on an auto increment field and some versions of MySQL do not like recieving a blank string as a value for auto increment fields. I also removed the single quotes from around categories_id since it is an integer not a string.

Didn't help and that shouldn't effect it anyways.

I'm confused. 

Are you wanting to put 1-17659 for each categoryid pulled from the database?

 

something like this

productid    categoryid

1                  1

2                  1

3                  1

..to 17659

1                  2

2                  2

3                  2

..to 17659

 

Yes,

products_id  categories

1                    76

2                    76

3                    76

4                    76

to 17659..

This should do it. There's probably a more efficient way, but this should work.

error_reporting(E_ALL);
$con = mysql_connect('localhost', 'root', '');
   if (!$con) {
      die('Connection Error:' . mysql_error());
   }
mysql_select_db('catgories', $con);
      
for($i=0;$i<=17659;$i++)
{
$query="INSERT INTO categories(`products_id`,`categories_id`) select $i,categories_id from categories"; 
mysql_query($query);
}

This should do it. There's probably a more efficient way, but this should work.

error_reporting(E_ALL);
$con = mysql_connect('localhost', 'root', '');
   if (!$con) {
      die('Connection Error:' . mysql_error());
   }
mysql_select_db('catgories', $con);
      
for($i=0;$i<=17659;$i++)
{
$query="INSERT INTO categories(`products_id`,`categories_id`) select $i,categories_id from categories"; 
mysql_query($query);
}

 

Nope it didn't work with no errors. I'm telling you I couldn't figure it out.

Nothing gets inserted into the database and it throws no errors even with the e_all reporting method enabled. It takes awhile to go through all 17659 instances but it does not insert anything.

Add display_errors(1); below error_reporting and change your query call to

 

mysql_query($query) or trigger_error("SQL: $query, ERROR: " . mysql_error(), E_USER_ERROR);

 

Edit: oops forgot to add the actual error.

Having trouble remembering, doesn't a MySQL error need to be reported explicitly? In other words, if you tried to insert a non-unique value into a unique column, wouldn't you need to report the returned MySQL error explicitly in PHP?

What message do you get when using...

 

$query = "INSERT INTO categories (categories_id) VALUES (18)";

 

I'm not saying the functionality will work as you intend but it shouldn't throw an error.

Edit: The single quotes around the field names would have thrown an error, I just realised I left that in when I last posted this line.

Is this the entire code? If nothing it happening when the code is run you should almost certainly be getting an error message. Have you tried using view source to see what if any HTML is written to the browser?

cags: the same error

The html document contains an error now because we set it to tell us.

 

Fatal error: SQL: INSERT INTO categories(`products_id`,`categories_id`) select 0,categories_id from categories, ERROR: in F:\Xampp\xampplite\htdocs\categories.php on line 13

i added that and it threw this error:

Fatal error: SQL: INSERT INTO categories(`products_id`,`categories_id`) select 0,categories_id from categories, ERROR: in F:\Xampp\xampplite\htdocs\categories.php on line 13

Well I'm not sure what to say. You obviously haven't changed it as suggested because it's still outputting the SQL statement suggested by taquitosensei...

 

$query = "INSERT INTO categories (categories_id) VALUES (18)";

gonna give the thread starter a heads up on how to get help...

 

this...

I have 17659 entries that are all the same. There are only two fields in the mysql databse Products_id witch auto increments and categories_id witch is an int 10.

 

This source code throws no errors.

means nothing to me, and 99% of the rest of the people on the board.

 

next time, be very descriptive as to what the problem is, the errors that you are receiving, and what you are trying to acheive .. because right off the bat, you lose over 50% of the people who are capable of creating a solution very quickly, like myself.

 

and i'm not going to read all the other posts in the thread just to try and figure out YOUR problem.

 

i love to help, but i only have so much time, and that time was just spent explaining to you how to get what you came for .. a solution.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.