kabar916 Posted October 7, 2011 Share Posted October 7, 2011 Whats up you guys. how can i insert an array into sql? How can i put the values of an array into table format (csv format) so i can upload it to sql, unless i can do it straight from an array? I hope that make sense. Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/ Share on other sites More sharing options...
gristoi Posted October 7, 2011 Share Posted October 7, 2011 Have a look at serialize Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1276746 Share on other sites More sharing options...
AyKay47 Posted October 7, 2011 Share Posted October 7, 2011 adding to what the previous poster stated.. user serialize to convert the array into a storable string for database storage.. then use unserialize when grabbing the string from the database to convert it into array format again... Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1276760 Share on other sites More sharing options...
kabar916 Posted October 8, 2011 Author Share Posted October 8, 2011 Thank you for your reply. I do have a another question though. After i use the serialize function, do i just use regular INSERT INTO function to insert the $serialize variable into the database? Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277147 Share on other sites More sharing options...
trq Posted October 8, 2011 Share Posted October 8, 2011 Before you go ahead and simply store an array in a format that is near useless for searching. What exactly does this array contain and will the data be used for? If you going to need to manipulate it or search for it while it is in a database then serialising it is a bad option. Instead, you should store it as normalised data, maybe even key value pairs. We need more details about what the data actually is for. Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277148 Share on other sites More sharing options...
kabar916 Posted October 8, 2011 Author Share Posted October 8, 2011 This is what im getting: a:603:{i:0;s:14:"17-1126-01.jpg";i:1;s:14:"17-1124-01.jpg";i:2;s:14:"17-1118-00.jpg";i:3;s:14:"17-1108-01.jpg";i:4;s:14:"17-1106-01.jpg";i:5;s:14:"17-1104-01.jpg";i:6;s:14:"17-1102-01.jpg";i:7;s:14:"17-1100-01.jpg";i:8;s:14:"17-1096-01.jpg";i:9;s:14:"17-1070-66.jpg";i:10;s:14:"17-0001-01.jpg";i:11;s:14:"15-5021-01.jpg";i:12;s:14:"15-5019-01.jpg";i:13;s:14:"15-5017-01.jpg";i:14;s:14:"12-5257-00.jpg";i:15;s:14:"12-5255-01.jpg";i:16;s:14:"12-5253-00.jpg";i:17;s:14:"12 How can i insert this into the database? Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277150 Share on other sites More sharing options...
trq Posted October 8, 2011 Share Posted October 8, 2011 You must have misread my reply. Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277151 Share on other sites More sharing options...
kabar916 Posted October 8, 2011 Author Share Posted October 8, 2011 I have a folder of images. i want to get a list of names of the images and make a table out of it in sql. Just the name of the images, not the image itself. i already made the table in sql, i just need to import the names. Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277167 Share on other sites More sharing options...
trq Posted October 8, 2011 Share Posted October 8, 2011 Sounds like it would be best to add each image to a separate row. Simply loop through the array and insert each image. Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277304 Share on other sites More sharing options...
kabar916 Posted October 9, 2011 Author Share Posted October 9, 2011 thanks alot thorpe. you help answer my question. i got it working. thanks once more! Quote Link to comment https://forums.phpfreaks.com/topic/248604-array-insert-into-sql/#findComment-1277344 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.