TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-13-2008, 04:10 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default 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?
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-13-2008, 04:51 AM   #2 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

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.)
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
The Following User Says Thank You to Andrew For This Useful Post:
Orc (02-13-2008)
Old 02-13-2008, 04:53 AM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Andrew View Post
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.)
list them off? What do you mean?
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-13-2008, 09:55 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

He means serialization. Something like:

Code:
path1|path2|path3
And then explode by the |.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-13-2008, 10:00 PM   #5 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
He means serialization. Something like:

Code:
path1|path2|path3
And then explode by the |.
But I want to output those files paths. Then I would have to do a pattern match, cause it's a path.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 01:02 AM   #6 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

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.gif
You would then select that field from your database and use something like:

PHP Code:
$filePaths explode('|'$result['filepaths']); 
The $filePaths variable would then contain an array that looked something like:

PHP Code:
// [0] => '/home/www/images/file1.png'
// [1] => '/home/www/images/file2.jpg'
// [2] => '/home/www/images/file3.gif' 
Which you could then manipulate as you wished.

To re-serialize the data, just use the implode() function.

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following User Says Thank You to Alan @ CIT For This Useful Post:
Orc (02-14-2008)
Old 02-14-2008, 01:05 AM   #7 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Alan @ CIT View Post
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.gif
You would then select that field from your database and use something like:

PHP Code:
$filePaths explode('|'$result['filepaths']); 
The $filePaths variable would then contain an array that looked something like:

PHP Code:
// [0] => '/home/www/images/file1.png'
// [1] => '/home/www/images/file2.jpg'
// [2] => '/home/www/images/file3.gif' 
Which you could then manipulate as you wished.

To re-serialize the data, just use the implode() function.

Alan
Oh thanks! I've never really tried explode, so I wouldn't know if that happened or not. I just thought when it exploded it did this:
PHP Code:
[0] => '/home/www/images/file1.png/home/www/images/file2.jpg/home/www/images/file3.gif' 
Thanks for clearing that up :D
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 02-14-2008, 10:00 AM   #8 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

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
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 02-14-2008, 04:19 PM   #9 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Quote:
Originally Posted by EyeDentify View Post
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

Thats just ignorant...

anyways search up:

PHP: serialize - Manual could be helpful in your case.
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
The Following User Says Thank You to Nor For This Useful Post:
Orc (02-14-2008)
Old 02-17-2008, 04:29 AM   #10 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

try trowing all the paths into a variable like

Code:
$variable = $path[1]."|".$path[2]."|".$path[3];

$query = "INSERT INTO somename(id,path) VALUES(null,'$path')";
$save = mysql_query($query);
your table structure should be

Code:
create table somename(id NOT NULL ,path mediumblob)
ENGiNE = myisam (or whatever u choose);

then you can do like

Code:
$query = "SELECT path FROM somename";
$output = mysql_query($query);

if(mysql_num_rows($output)) { 


while($row = mysql_fetch_assoc($output)) {

$data = $row['path'];
}

for($i=0;$i<count(data);$i++) {

echo $data[$i]."<br>";
}
}
let me know if this is what you needed, i got cared away :p
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 02-14-2008, 03:05 PM   #11 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
The Following 2 Users Say Thank You to Village Idiot For This Useful Post:
Orc (02-14-2008), SOCK (02-17-2008)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:47 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design