Trying to code a code submitter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dataangel
Forum Newbie
Posts: 12
Joined: Thu Aug 07, 2003 7:29 pm

Trying to code a code submitter

Post 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?
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Re: Trying to code a code submitter

Post 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.....)
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post 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. :)
dataangel
Forum Newbie
Posts: 12
Joined: Thu Aug 07, 2003 7:29 pm

Post 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.
dataangel
Forum Newbie
Posts: 12
Joined: Thu Aug 07, 2003 7:29 pm

Post 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 :P
dataangel
Forum Newbie
Posts: 12
Joined: Thu Aug 07, 2003 7:29 pm

Post by dataangel »

*shameless bump*
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
Post Reply