Reply
HTML checkbox form, storing hours worked, my method == BAD!
Old 04-05-2008, 06:25 PM HTML checkbox form, storing hours worked, my method == BAD!
Skilled Talker

Posts: 83
Well, I have this form of text boxes.....

HTML Code:
<table border="1" bordercolor="#000000" cellpadding="5" cellspacing="0">
                <tbody>
                <tr>
                    <td>HOUR</td>
                        <td align="center">SUN</td>
                        <td align="center">MON</td>
                        <td align="center">TUE</td>
                        <td align="center">WED</td>
                        <td align="center">THU</td>
                        <td align="center">FRI</td>
                        <td align="center">SAT</td>
                </tr>
                
                    <tr>
                        <td>8:00 - 9:15 AM</td>
                            <td align="center"><input name="1_800" value="1" type="checkbox"></td>
                            <td align="center"><input name="2_800" value="1" type="checkbox"></td>
                            <td align="center"><input name="3_800" value="1" type="checkbox"></td>
                            <td align="center"><input name="4_800" value="1" type="checkbox"></td>
                            <td align="center"><input name="5_800" value="1" type="checkbox"></td>
                            <td align="center"><input name="6_800" value="1" type="checkbox"></td>
                            <td align="center"><input name="7_800" value="1" type="checkbox"></td>
                    </tr>
                
                    <tr>
                        <td>9:45 - 11:00 AM</td>
                            <td align="center"><input name="8_945" value="1"  type="checkbox"></td>
                            <td align="center"><input name="9_945" value="1"  type="checkbox"></td>
                            <td align="center"><input name="10_945" value="1"  type="checkbox"></td>
                            <td align="center"><input name="11_945" value="1"  type="checkbox"></td>
                            <td align="center"><input name="12_945" value="1"  type="checkbox"></td>
                            <td align="center"><input name="13_945" value="1"  type="checkbox"></td>
                            <td align="center"><input name="14_945" value="1"  type="checkbox"></td>
                    </tr>
                
                    <tr>
                        <td>11:15 - 12:30 PM</td>
                            <td align="center"><input name="15_1115" value="1" type="checkbox"></td>
                            <td align="center"><input name="16_1115" value="1"  type="checkbox"></td>
                            <td align="center"><input name="17_1115" value="1"  type="checkbox"></td>
                            <td align="center"><input name="18_1115" value="1"  type="checkbox"></td>
                            <td align="center"><input name="19_1115" value="1"  type="checkbox"></td>
                            <td align="center"><input name="20_1115" value="1"  type="checkbox"></td>
                            <td align="center"><input name="21_1115" value="1" type="checkbox"></td>
                    </tr>
                
                    <tr>
                        <td>1:00 - 2:15 PM</td>
                            <td align="center"><input name="22_100" value="1"  type="checkbox"></td>
                            <td align="center"><input name="23_100" value="1"  type="checkbox"></td>
                            <td align="center"><input name="24_100" value="1"  type="checkbox"></td>
                            <td align="center"><input name="25_100" value="1"  type="checkbox"></td>
                            <td align="center"><input name="26_100" value="1"  type="checkbox"></td>
                            <td align="center"><input name="27_100" value="1"  type="checkbox"></td>
                            <td align="center"><input name="28_100" value="1"  type="checkbox"></td>
                    </tr>
                
                    <tr>
                        <td>2:30 - 3:45 PM</td>
                            <td align="center"><input name="29_230" value="1" type="checkbox"></td>
                            <td align="center"><input name="30_230" value="1" type="checkbox"></td>
                            <td align="center"><input name="31_230" value="1"  type="checkbox"></td>
                            <td align="center"><input name="32_230" value="1"  type="checkbox"></td>
                            <td align="center"><input name="33_230" value="1"  type="checkbox"></td>
                            <td align="center"><input name="34_230" value="1"  type="checkbox"></td>
                            <td align="center"><input name="35_230" value="1"  type="checkbox"></td>
                    </tr>
                
                    <tr>
                        <td>4:25 - 5:30 PM</td>
                            <td align="center"><input name="36_425" value="1" type="checkbox"></td>
                            <td align="center"><input name="37_425" value="1" type="checkbox"></td>
                            <td align="center"><input name="38_425" value="1" type="checkbox"></td>
                            <td align="center"><input name="39_425" value="1" type="checkbox"></td>
                            <td align="center"><input name="40_425" value="1" type="checkbox"></td>
                            <td align="center"><input name="41_425" value="1" type="checkbox"></td>
                            <td align="center"><input name="42_425" value="1" type="checkbox"></td>
                    </tr>
                
                    <tr>
                        <td>6:30 - 7:45 PM</td>
                            <td align="center"><input name="43_630" value="1" type="checkbox"></td>
                            <td align="center"><input name="44_630" value="1" type="checkbox"></td>
                            <td align="center"><input name="45_630" value="1" type="checkbox"></td>
                            <td align="center"><input name="46_630" value="1" type="checkbox"></td>
                            <td align="center"><input name="47_630" value="1" type="checkbox"></td>
                            <td align="center"><input name="48_630" value="1" type="checkbox"></td>
                            <td align="center"><input name="49_630" value="1" type="checkbox"></td>
                    </tr>
                
                    <tr>

                        <td>8:15 - 9:30 PM</td>
                            <td align="center"><input name="50_815" value="1" type="checkbox"></td>
                            <td align="center"><input name="51_815" value="1" type="checkbox"></td>
                            <td align="center"><input name="52_815" value="1" type="checkbox"></td>
                            <td align="center"><input name="53_815" value="1" type="checkbox"></td>
                            <td align="center"><input name="54_815" value="1" type="checkbox"></td>
                            <td align="center"><input name="55_815" value="1" type="checkbox"></td>
                            <td align="center"><input name="56_815" value="1" type="checkbox"></td>
                    </tr>
                
            </tbody></table>
what happens is you check when you can work, and then it gets registered....well the way I'm registering is into one array, that gets put into one column into the database. My method now is this...

PHP Code:
for($day 1$day <= 7$day++)
{
    if(
$_REQUEST[$day "_800"] != NULL)
    {
        
$dayArray[$day] = 1;
        echo 
$_REQUEST[$day "_800"] . '<br />';
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 9:45-11:00
for($day 8$day <=14$day++)
{
    if(
$_REQUEST[$day "_945"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 11:15-12:30pm
for($day 15$day <=21$day++)
{
    if(
$_REQUEST[$day "_1115"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 1:00-2:15pm
for($day 22$day <=28$day++)
{
    if(
$_REQUEST[$day "_100"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 2:30-3:45PM
for($day 29$day <=35$day++)
{
    if(
$_REQUEST[$day "_230"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 4:25-5:30PM
for($day 36$day <=42$day++)
{
    if(
$_REQUEST[$day "_425"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 6:30-745pm
for($day 43$day <=49$day++)
{
    if(
$_REQUEST[$day "_630"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }
}

//STORING HOURS WORKED FOR 8:15-9:30pm
for($day 50$day <=56$day++)
{
    if(
$_REQUEST[$day "_815"] != NULL)
    {
        
$dayArray[$day] = 1;
    }
    else
    {
        
$dayArray[$day] = 0;
    }

Then I use serialize and unserialize so the database can register all the values. To me this seems as inefficient as it gets. Anyone have any ideas to make this a lot better? Thanks you very much!

Last edited by kbfirebreather : 04-05-2008 at 06:40 PM.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-07-2008, 01:52 AM Re: HTML checkbox form, storing hours worked, my method == BAD!
mtishetsky's Avatar
Super Spam Talker

Posts: 865
Location: Volendam, Netherlands
Describe what you are trying to do in human friendly way, not with your scripts.
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-07-2008, 03:17 AM Re: HTML checkbox form, storing hours worked, my method == BAD!
Ultra Talker

Posts: 308
Yes, that is inefficient. What information do you need to store in your database, just the total number of hours worked per week or do you need to store the exact timing of work as well?
__________________
tiny url
dman_2007 is offline
Reply With Quote
View Public Profile Visit dman_2007's homepage!
 
Old 04-07-2008, 10:57 AM Re: HTML checkbox form, storing hours worked, my method == BAD!
Skilled Talker

Posts: 83
Well, here is the table for the hours... I'm trying to store the exact hours they do work, and what happens with the current code is 8-915 am is stored as 1-7 (sun-sat), 9:45-11:00 am stored as 8-14(sun-sat), etc, etc. But I have the requests setup as 1_800 (for 8-9:15 am), etc, etc.
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to HTML checkbox form, storing hours worked, my method == BAD!
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16759 seconds with 13 queries