PDA

View Full Version : Writing a piece of code...


Radon3k
01-21-2003, 04:21 AM
Hi there,

I'm developing something and now I'm stuck on it. This may sound weird, but I do have a point behind it, so please bare with me. For right now, I just want the simple procedure, and if that's successful, then I'll take it to the next step.

I have a text file that contains several thousand company names in it. What I want to be able to do, using the "add forum" section from /admin/forum.php, is have it read each line of the text file and create a category name for each company listed there.

Example:

Microsoft
Circuit City
Best Buy

When the script is executed, a category for Microsoft, a category for Circuit City, and a category for Best Buy would be created. To add onto that, with each category created, 4 forums would be added as well, all having the same names.

Example:

Category names:
Microsoft
Circuit City
Best Buy

Forum names:
General talk
What To Buy
What's On Sale

When the script is executed:

Microsoft
--General Talk
--What To Buy
--What's On Sale

Circuit City
--General Talk
--What To Buy
--What's On Sale

Best Buy
--General Talk
--What To Buy
--What's On Sale

You get the idea. I know that I need to use a loop (probably going to use a "for" loop) for this, but I'm unsure of how to import the file. To add onto that, I'm having trouble figuring out how to add it to the forums with the code from /admin/forum.php.

I've tried adding just one forum using an HTML form, but that did not work.

I'm thinking that I need to make the text file into a PHP file and make the company names an array. Though, that sounds like a lot of work for several thousand companies. If this were 10 companies, I'd add them manually via the Admin CP in vBulletin, but several thousand companies is a lot of work.

I know you're probably asking, "Why on Earth would you want to do that?". Please just bare with me.

Any guidance in the right direction would be most appreciative. Thanks! :)

mr e
01-21-2003, 09:55 PM
couldn't you do it with just a query to the db, to get it from the text file explode it into an array then count the array and do for($i=0;$i<array;$i++) then a query to make a forum, look at what query vb does when you tell it to create one and use that

Radon3k
01-21-2003, 10:08 PM
Yeah I did look at that, but there's a few there and I'm not sure which one to use. :)

mr e
01-21-2003, 10:54 PM
you could try this to open the file, just make sure each entry is seperated by a space


$file = file_get_contents ("file.txt");
$filearray = explode (" ", $file);

$i = 0;
for ($i=0;$i<$filearray-1;$i++) {
RUN QUERY HERE
}


i think that'll work, but im no php guru or anything

mr e
01-21-2003, 11:07 PM
then for the query i think this'll work


$pid = $i + 1;
$DB_site->query("INSERT INTO forum
(forumid,styleid,title,description,active,displayo rder,parentid,
parentlist,allowposting,cancontainthreads,daysprun e,newpostemail,newthreademail,
moderatenew,allowhtml,allowbbcode,allowimages,allo wsmilies,allowicons,
styleoverride,allowratings,countposts,moderateatta ch)
VALUES
(NULL,'YOUR DEFAULT STYLE','$filearray[$i]','','1','$i','$pid',
'$i,-1','0','0','0','','','0','0','1','1','1','1','0',' 1',
'1','0')");

$DB_site->query("INSERT INTO forum
(forumid,styleid,title,description,active,displayo rder,parentid,
parentlist,allowposting,cancontainthreads,daysprun e,newpostemail,newthreademail,
moderatenew,allowhtml,allowbbcode,allowimages,allo wsmilies,allowicons,
styleoverride,allowratings,countposts,moderateatta ch)
VALUES
(NULL,'YOUR DEFAULT STYLE','General Talk','','1','$i','-1',
'$i,-1','1','1','30','','','0','0','1','1','1','1','0', '1',
'1','0')");

$DB_site->query("INSERT INTO forum
(forumid,styleid,title,description,active,displayo rder,parentid,
parentlist,allowposting,cancontainthreads,daysprun e,newpostemail,newthreademail,
moderatenew,allowhtml,allowbbcode,allowimages,allo wsmilies,allowicons,
styleoverride,allowratings,countposts,moderateatta ch)
VALUES
(NULL,'YOUR DEFAULT STYLE','What to Buy','','1','$i','-1',
'$i,-1','1','1','30','','','0','0','1','1','1','1','0', '1',
'1','0')");

$DB_site->query("INSERT INTO forum
(forumid,styleid,title,description,active,displayo rder,parentid,
parentlist,allowposting,cancontainthreads,daysprun e,newpostemail,newthreademail,
moderatenew,allowhtml,allowbbcode,allowimages,allo wsmilies,allowicons,
styleoverride,allowratings,countposts,moderateatta ch)
VALUES
(NULL,'YOUR DEFAULT STYLE','What's on Sale','','1','$i','-1',
'$i,-1','1','1','30','','','0','0','1','1','1','1','0', '1',
'1','0')");


the only thing i can't get to work is the parent list thing so i dont know if this will even work until you get those working, but i haven't tested this

Radon3k
01-21-2003, 11:29 PM
Yeah I had a hard time with the parent ID thing too. Ok well lemme mess around with this code and I'll get back to you. Thanks a bunch, sir! :)