Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with basic script!

    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:
    PHP Code:
    $res = mysql_fetch_assoc(mysql_query("SELECT * FROM school_data")); 
    $row=mysql_fetch_assoc($res)
    $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 !="")
    mysql_query($update);
    echo $school" -1";
    }
    elseif ($virtual_number =="0");
    {
        echo "<? echo "$school"?> is now PAUSED!";
        mysql_query($pause);    
    }
    else
    {
        echo $school "Lead Successfull!"
        mysql_query($credit);
        echo $school "Credited +1 Successful";
    can someone just please fix this for me? Thank you!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.

    Code:
    Employee Table
    =======================
    ID     Name
    -----------------------
    100    Fred
    101    Ted
    102    Sned
    103    Zed
    
    
    School Table
    =======================
    ID
    -----------------------
    200    Devry
    201    ITT
    202    MIT
    203    LDS Business College
    And now here is the table you insert into from submitting the form:

    Code:
    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:

    Code:
    SELECT COUNT(*)
    FROM FormData
    WHERE School = 200
    Likewise, you can find the score of an employee:

    Code:
    SELECT COUNT(*)
    FROM FormData
    WHERE Employee = 102
    You'll probably need something a bit more complex, but this is the basic concept.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •