Jump to content


Photo

copying and inserting related records into 2nd table? error...


  • Please log in to reply
1 reply to this topic

#1 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 19 August 2006 - 03:42 AM

hi people

i'm trying to copy all the records that is related to my search.
my first table is 'topics',
and the 2nd table is 'topics_tmp'.

and the codes that producing an error is here below,
//Empty temporary table topics_tmp then fill again with contents from topic_rel[]
	for($x=0; $x<=$total_rec; $x++){
		//select records from table TOPICS first
		$query  = "SELECT * FROM topics WHERE id='$topic_rel[$x]'";
		$result = mysql_query($query) or die('Error, query failed');
		$row = mysql_fetch_array($result, MYSQL_ASSOC);
		$id_tmp = $row['id'];
		$title_tmp = $row['title'];
		$descrip_tmp = $row['description'];
		$url_tmp = $row['url'];
		
		//then insert selected data into TOPICS_TMP temporary table
		$query = "INSERT INTO topics_tmp (id, title, description, url) VALUES ('$id_tmp', '$title_tmp', '$descrip_tmp', '$url_tmp')";
		mysql_query($query) or die('Error, insert query failed');
		
	}

when i execute it the error message is showing up -->'Error, insert query failed'.
now what was my mistake here? am i doing the right copying from 1st table
and inserting the records into 2nd table?
Or do i have syntax error here?

Thank you very much in advance... for your kind help.



#2 bilis_money

bilis_money
  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 19 August 2006 - 03:47 AM

and by the way i am using 'topic_rel[]' an array as my temporary storage of all related topics. am i using it the right way?

thanks again.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users