Page 1 of 1
Trying to code a code submitter
Posted: Tue Aug 19, 2003 9:58 pm
by dataangel
I'm trying to setup a website where people can upload new functions they've coded in JASS (the scripting language that the game WarCraft3 uses). I plan to do this using PHP/MySQL.
When the user submits a new function, one of the fields I want them to be able to fill in is a box where they can enter the names of other user submitted functions that this function is dependent upon. The problem is that some functions will be dependant on 10 others, while some will only be dependant on 3, and so on. I have no way to predict it. So two questions:
1. Using PHPMyAdmin, how do I set it up so I can store a variable amount of contents in a table cell?
2. What MySQL type would be best suited for this? Convert the names of the functions they enter to their id numbers and store them as a bunch of integers? Verify that the string for the function they enter exists and store it as a string?
And my last question is about formatting. I want comments in code to automattically be highlighted grey. How do I scan each line for // and make everything after it on that line grey?
Re: Trying to code a code submitter
Posted: Tue Aug 19, 2003 10:09 pm
by nielsene
dataangel wrote:
When the user submits a new function, one of the fields I want them to be able to fill in is a box where they can enter the names of other user submitted functions that this function is dependent upon. The problem is that some functions will be dependant on 10 others, while some will only be dependant on 3, and so on. I have no way to predict it. So two questions:
1. Using PHPMyAdmin, how do I set it up so I can store a variable amount of contents in a table cell?
2. What MySQL type would be best suited for this? Convert the names of the functions they enter to their id numbers and store them as a bunch of integers? Verify that the string for the function they enter exists and store it as a string?
Sounds like you need to have two tables:
Something like
Code: Select all
create table user_submitted_code (
codeid AUTO_INCREMENT PRIMARY KEY,
functionname text,
functionbody text,
submittor int references user_table on update cascade on delete restrict,
date_submitted timestamp
);
create table user_code_depend (
codeid int references user_submitted_code on update cascade on delete cascade,
dependid int references user_submitted_code on update cascade on delete cascade,
primary key (codeid,dependid)
);
Now you can enter one how into the second table for each dependency without worrying about how many there will be in advance.
NOTE: I am a PostGreSQL user. I don't know if MySQL has the types/syntax I used above, but I hope you can understand what I'm getting at. (I do know that MySQL uses Auto_increment and not SERIAL as I'm used to, but other than that.....)
Posted: Wed Aug 20, 2003 6:30 am
by will
nielsene gave you a good database schema, so here's how to color the comments.
Code: Select all
//-- retrieve function body from database and store in variable $body
$body = preg_replace('/\/\/$/m','<span style="color:#999;">\\0</span>', $body);
friendly HTML reminder: use span or something similar... never <font>. it's deprecated, doesn't seperate content and presentation, and is generally evil.

Posted: Sun Aug 24, 2003 8:45 pm
by dataangel
nielsene: Unfortunately I'm not experienced enough with SQL period to get what you're doing. Inparticular, I have no idea what this line does:
Code: Select all
submittor int references user_table on update cascade on delete restrict
I'm not sure how I'd modify that element in the table either.
Posted: Sun Aug 24, 2003 8:45 pm
by dataangel
will wrote:nielsene gave you a good database schema, so here's how to color the comments.
Code: Select all
//-- retrieve function body from database and store in variable $body
$body = preg_replace('/\/\/$/m','<span style="color:#999;">\\0</span>', $body);
friendly HTML reminder: use span or something similar... never <font>. it's deprecated, doesn't seperate content and presentation, and is generally evil.

Could you explain what each part of that function is doing? I understand the span tag of course, but I'm unsure what '/\/\/$/m' is

Posted: Tue Aug 26, 2003 6:18 pm
by dataangel
*shameless bump*
Posted: Tue Aug 26, 2003 6:44 pm
by Unipus
It's a regular expression that searches for "//" and replaces it. Regular expressions are really difficult to read by eye, but very powerful.
As for the
Code: Select all
submittor int references user_table on update cascade on delete restrict
... that's just the definition for one of the table columns. I can't say that I understand everything that it does because I've never seen most of those attributes before, but basically it's a set of rules for determining how that column works. Once the rules are set you don't actually have to interact with them again.