While loop only using first row

Hi,

I’m trying to update my DB with all the data from another table. The problem is the loop only uses the first row in temp, but does its job too many time.

Table temp has 1000 rows.

Table products ends up with 5008 identical rows (apart from primary key). All data is from row 1 of temp.


public function insertBloodyProducts(){
	$q = "SELECT * FROM ".DB_PREFIX."temp";
	
	while($result = $this->query($q)){
		$row = $this->fetch_assoc($result);
		$cleanURL = preg_replace('/[^a-zA-Z0-9]/i','-',$row['tempName']);
		$cleanURL = preg_replace('/ /i','-',$cleanURL);
		$categories = array("161"); //Array for future additions
		
	
	
	$data = array(...);
		
	$q1 = $this->insertProductQuery($data);

	$result1 = $this->query($q1);

}

}

This has been driving me crazy. Can anyone see where I’m going wrong?

Cheers,
Rhys

Yep, your while loop is using the QUERY and not the results of the query
while($result = $this->queryCOLOR=#007700){
[/COLOR]$row = $this->fetch_assocCOLOR=#007700;

$result = $this->queryCOLOR=#007700;
while([/COLOR]$row = $this->fetch_assocCOLOR=#007700) { [/COLOR][/COLOR]

Thanks, I changed that earlier trying to fix another issue. That fixed the issue with the first row. But it still seems to insert 2 of everything. Not too sure why?

Nevermind. The function was run twice because of another function on the page. All sorted. Thanks.

Are you saying you want to ultimately:

a) copy the contents of one table to a temp one
b) edit slightly the column of the new temp one when it has been filled

?

No it’s an ecommerce site for a client. I often get sent enormous CSVs full of products. But it is expected they just “slot in”. But with so many different tables and fields, I’ve found its best to put them into a temp table and call a function to run through it and execute it as it would if they used the “New Product” form. All sorted now, but where are data entry employees these days? You build a nice easy CMS/ecommerce system, but it’s still your job to use it. :eek:

Cheers,
Rhys

Just to say there is a REPLACE function in Mysql which may not be as easy to write as PHP, but would probably be quicker to run, in case you did not know.