- - NC - - Posted February 3, 2009 Share Posted February 3, 2009 Hi everybody! First post, of many. I am new to all this so please bare with me if my code is a little lame :-\ I have this code which takes a url from my sql database, extracts the filename from the url, copies the image from the url to the local server and names it with the extracted filename: $result = mysql_query("SELECT url_info FROM table1"); while($row = mysql_fetch_array( $result )) { $url = $row[File_url]; $file_name = basename($url); echo "<img src=\"".$row[File_url]."\" />"; copy($row[File_url], "images/$file_name"); } This works fine, but I also need to copy the file name for each url to another table. I have this code, which is wrong because it inserts too many records. it takes $file_name from the code above. mysql_query("INSERT INTO table2 (idcode, listingsimages_file_name, listingsdb_id, listingsimages_rank, listingsimages_active) SELECT '2', '$file_name', ID, File_index, 'yes' FROM table1;"); example: 8 images, creates 64 records id1 image1 id1 image2 id1 image3 id1 image4 id1 image5 id1 image6 id1 image7 id1 image8 id2 image1 id2 image2 id2 image3 etc........ when all I want is: id1 image1 id2 image2 id3 image3 etc........... I'm sure there is a simple (yet unknown to me) explanation here. Please help!!! Thanks Nick Quote Link to comment https://forums.phpfreaks.com/topic/143703-please-help-write-to-sql-within-while-statement/ Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 Can you show us your whole code? Quote Link to comment https://forums.phpfreaks.com/topic/143703-please-help-write-to-sql-within-while-statement/#findComment-754010 Share on other sites More sharing options...
HuggieBear Posted February 4, 2009 Share Posted February 4, 2009 Are you also able to provide the structure of the two database tables? That would help too. Regards Rich Quote Link to comment https://forums.phpfreaks.com/topic/143703-please-help-write-to-sql-within-while-statement/#findComment-754266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.