agf2309 Posted May 9, 2009 Share Posted May 9, 2009 Hi everyone, I am trying to build a script that will take data from a text file and get a number of filenames from the text. I've managed to get it to do this. I then want to UPDATE the filenames into my table. The filenames are image names. So for example each row in the table might have multiple images in the "allimages" field. So far I have amanged to get these individual filenames and now I want to update them to fields called "pic1", "pic2" etc through "pic15". What I am trying to do is to get the script to name the column that the filename goes into. e.g. 1st pic goes into "pic1" etc. I have set a variable for $col="pic" and I want to create a variable called $colno=$col[$i]; where $i increments dependent on the no of pictures in the text file. This is probably as clear as mud. I have inserted my code so far below, Maybe someone can help me or point me in the right direction. Thanks. Tony <?php do { // Begin PHP if($row_images['allimages']!=""){ $data = preg_split("/;/", $row_images['allimages'], 15, PREG_SPLIT_NO_EMPTY);// get each URL from DB for($c=0; $c < count($data); $c++){// for statement 1 $url=$data[$c]; }// end of for statement 1 }// end of opening if statement foreach($data as $key => $line){// forech statement 1 - explode data array to get file name $pics = explode("http://82.195.133.221/vehicleimages/used/", $line, 15); for($i = 1; $i < count($pics); $i++){//for statement 2 foreach($pics as $key => $value){//foreach statement 2 $pic=$pics[$i]; $stockno=$row_images['stockno']; for($a=0; $a<=count($data); $a=$a+1) { $col="pic"; $colno=$col.$a; } }// end of foreach statement 2 echo $colno. " = ". $pic.$stockno."(".count($data).")<br />"; } // end of for statement 2 }// end of foreach statement 1 }// end cury brace for start of PHP while ($row_images = mysql_fetch_assoc($images)); ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 9, 2009 Share Posted May 9, 2009 Hold up. You have columns in your table named pic1 through pic15? That's a bad design. It's hard to maintain and hard to change. It's also hard to search with anything other than the most basic search. I'd suggest you alter your database design to have a separate table for the pictures, linked to your main table by a unique ID. You might like to read up about database normalization and have a read of this tutorial: http://www.phpfreaks.com/tutorial/data-joins-unions Quote Link to comment 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.