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