View Full Version : need help with basic script!

04-02-2010, 03:31 PM
Ok so i am new to the forums, and new to php as well.

What i am trying to do is: I have a large form with 3 drop downs at the bottom that are "School_1", "School_2", and "School_3". school_1, school_2, and school_3 are Columns in that person's record..basically i filled out a form with a persons information and assigned them 3 schools. (first name, last name, address, school_1, school_2, school_3) etc..So basically per record, it'll be like Brandon Smith, blah balh, School of Rock , ITT Tech , and DeVry University. and thats 1 record on table School_data. (so those people's records are on SCHOOL_DATA, and our employee's are on EMPLOYEE_INFO)

What my goal is: When you press submit on the form, it'll add all the fields to a database (which it already does..so thats complete(it's the added.php included at the top)), but i also need to process the information, meaning, for whatever school was used in the school_1, school_2, school_3 slots, ALL get "-1" from their $virtual_number(column Virtual_number (INT)). and if they're virtual_number hits "0", CHANGE status to PAUSED, and it wont populate in my drop downs (because only status =="live" populate in dropdowns). So not just will it -1, from the schools that were used in the 3 slots, also "+1" for each Successful School processed, to column "web" WHERE employee="$employee", So who's ever name is on the bottom in the EMPLOYEE field, gets credit for the slots that have schools in them.

So if Joseph Processed school_1, school_2, and school_3, the 3 schools get -1 from their virtual_number, and Joseph gets +3 to WEB. Here is a rough (and proabbly wrong) script i have..

Other things to know. All 3 slots might not be filled everytime, could be 1,2 or 3. So if school_1 != "", continue script. (so if it's NOT empty, process slot 1) and each if statement for EACH slot (total of 3).

What i have so far is most likely wrong syntax, which is what im trying to get help on. I had planned to just have the script run for school_1 and just copy and paste it, but i could put into an array. and just loop it through?

i know pretty much nothing about php, so if someone can just build this out for me, with what i have so far, just fix it - that would be very helful and i could understand how its done. I googled high and low, and thats how i came up with this, but i just need help finishing it.

someone has posted on this forum and a differnet one in the past, and thats how i found that virtual_number concept because it's so close to what i need - he had it in a button, i need to run it in a script.., i've tried contacting that person, no luck yet.
the code:

$res = mysql_fetch_assoc(mysql_query("SELECT * FROM school_data"));
$update = "UPDATE school_data SET $virtual_number = $virtual_number - 1 WHERE name=' . $row['name']'";
$credit = "UPDATE employee_info SET $web = $web + 1 WHERE employee='$employee'";
$schools = array('school_1', 'school_2', 'school_3');
$pause = "UPDATE school_data SET status='PAUSED' WHERE name=' . $row['name'] . "-" . $row['cid'] . '";

foreach($schools as $school) {
$school = $school;

if ($school !="")
echo $school" -1";
elseif ($virtual_number =="0");
echo "<? echo "$school"; ?> is now PAUSED!";
echo $school "Lead Successfull!"
echo $school "Credited +1 Successful";

can someone just please fix this for me? Thank you!

04-02-2010, 06:09 PM
I think I understand. Maybe. You are keeping some sort of "score" (you're calling it virtual_number for some reason) for a list of schools, and you are keeping some sort of "score" (you call it "web" for some reason) for your employees.

The design you would like to use may work out OK, but let me recommend another concept. If you keep your data well organized (that is to say, "normalized"), you can use the power of MySQL to tally these scores anytime you need to see them, rather than store the scores in a table. The advantage to doing this is you lessen the risk of something going wrong with the score you've been tallying over time and then you have no way of knowing what the score really should be.

So... let's say instead of storing all three schools from one employee in a single row, you store only one school in a row. Also, let's assign each school a unique numeric ID, instead of using the name of the school. (The advantage here is, if a school's name changes, or has been misspelled, you only have to change it in one spot, rather than in 5,000 spots. Also, MySQL is better at accessing data when you use numeric keys.) Let's do the same for Employees.

Employee Table
ID Name
100 Fred
101 Ted
102 Sned
103 Zed

School Table
200 Devry
201 ITT
202 MIT
203 LDS Business College

And now here is the table you insert into from submitting the form:

FormData Table
FormID Employee School
1 100 200
1 100 201
1 100 203
2 101 201
3 102 200
3 102 201
3 102 202

Now, it's an easy thing to find out how many times a school was selected, and you don't have to store a score:

FROM FormData
WHERE School = 200

Likewise, you can find the score of an employee:

FROM FormData
WHERE Employee = 102

You'll probably need something a bit more complex, but this is the basic concept.