![]() |
Storing multiple file paths inside a database
How do I store multiple file paths or files inside the database, for them to be in all in one id?
Say if I wanted to get the id of a file, but there were multiple files, how would I put them all together to one id? :S Or say I had two tables, one for title, description, and one for the id and files. How would I combine these? |
Instead of just using the ID field, you can create a row in the table named 'files', and you could list them off, separating them by a semicolon and storing them that way. (You can then use a function like explode() to get the into an array for any manipulation.)
|
Quote:
|
He means serialization. Something like:
Code:
path1|path2|path3 |
Quote:
|
Using the examples above, you'd end up with an array of the file paths that you could pattern match / output as you wished.
For example, say your files field in your database contained: Code:
/home/www/images/file1.png|/home/www/images/file2.jpg|/home/www/images/file3.gifPHP Code:
PHP Code:
To re-serialize the data, just use the implode() function. Alan |
Quote:
PHP Code:
|
Do you at all look in the one place where info are to be found:
PHP: Hypertext Preprocessor ? If not you should really start. Itīs a great source of information about various functions and so on about PHP. Good luck. /EyeDentify |
Better to use a relational table or three fields on the table then explode it like that. It's never a good idea to store data like that. It's also bad for this purpose because | can go into a filename.In the unlikely event that someone sticks that in there, you have a problem on your hands.
|
Quote:
Thats just ignorant... anyways search up: PHP: serialize - Manual could be helpful in your case. |
try trowing all the paths into a variable like
Code:
Code:
create table somename(id NOT NULL ,path mediumblob)then you can do like Code:
$query = "SELECT path FROM somename"; |
| All times are GMT. The time now is 05:47 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0