Page 1 of 1

PHP sign-up table

Posted: Fri Jul 10, 2009 8:22 pm
by smccoy4
I am trying to create a table where users can sign-up to attend on certain days, certain times, and for certain jobs. I created the way I want the table to look in html and I am trying to have it so that the user can click on the signup image and tell which day, time, and job they would like to show up for. Where I am having problems is getting the data into the proper spots in the table. I am very new to php but not to programming and I am pretty sure my problem is most likely something small and silly. Any help would be greatly appreciated. You can see what I already have done here:
http://sts.indstate.edu/~jjaeger4/goode ... ables.html
http://sts.indstate.edu/~jjaeger4/goode ... ables.html

Please help, the original programmer on this is in England for a month and I don't have that long until it has to be done.

Re: PHP sign-up table

Posted: Sat Jul 11, 2009 1:27 pm
by Skara
404 on the link.

1) Take in the data from an HTML form.
2) Store the data in a database, e.g. MySQL.

Re: PHP sign-up table

Posted: Sat Jul 11, 2009 1:49 pm
by smccoy4
I apologize for that. I have managed to get it to work, but I'm pretty sure there is a much shorter and simplier way.

The new link is: http://sts.indstate.edu/~jjaeger4/goode ... tables.php

The save file and signup sheet you just replace the tables.php with save.php and signup.html

Re: PHP sign-up table

Posted: Sat Jul 11, 2009 1:57 pm
by Eric!
smccoy4 wrote:Where I am having problems is getting the data into the proper spots in the table. I am very new to php but not to programming and I am pretty sure my problem is most likely something small and silly.
This can be tricky, but it seems like your form works fine when I played with it. What is the problem?

Re: PHP sign-up table

Posted: Sat Jul 11, 2009 2:22 pm
by Skara
Functionally it almost seems to work. The only problem is that you can replace existing data, overwriting a previous sign-up.
Also, every link on the right is the same.

I would add a "signup" link on every square of the calendar if it isn't already taken.
As you loop through the days and times, simply code the link something like...

Code: Select all

<a href="signup.php?day=7&activity=02&time=1">sign up</a>
Then in signup.php...

Code: Select all

$times = array('10:00-12:00', '12:00-2:00', '2:00-4:00', ...);
//remember the index for 10:00-12:00 is 0, not 1
 
foreach ($times as $i => $time) {
    echo '<option value="', $i, '"';
    if (isset($_GET['time']) && $_GET['time'] == $i) {
        echo ' selected="selected"';
    }
    echo '>', $time, '</option>';
}
for that matter, I usually have an option function handy.

Code: Select all

function show_options($options, $selected=false) {
    foreach ($options as $i => $option) {
        echo '<option value="', $i, '"';
        if ($selected !== false && $selected == $i) {
            echo ' selected="selected"';
        }
        echo '>', $option, '</option>';
    }
}
//e.g.
show_options($times, $_GET['time']);

Re: PHP sign-up table

Posted: Sun Jul 12, 2009 9:05 am
by smccoy4
Thank you very much for the quick reply. And thank you for the great advice, I was unaware that I could do that in php. Like I said, I am a newb. I have only been using php for about a week. I will give your suggestion a try when I get back to the office on Monday.

Re: PHP sign-up table

Posted: Mon Jul 13, 2009 10:37 am
by smccoy4
I have tried what you said, but I am running into problems.

Code: Select all

 
"signup.php?day=7&activity=02&time=1"
 
For some reason, when I put this code in for the link, it puts the same information in for ever link. Regardless of which one. If I chose day 1 activity 3 time 2 it would fill in the same values as whatever the first link on the page is listed as.

After i click the link to sign up, the picture link does not go away and the database info is not entered into the table.

Re: PHP sign-up table

Posted: Mon Jul 13, 2009 3:39 pm
by Skara
Um.. that was an example.
I don't know what the loop for your table looks like, but for example..

Code: Select all

foreach ($days as $day) {
    echo '<h1>', $day['name'], '</h1><table>';
    foreach ($activities as $activity) {
        echo '<tr><td>', $activity['name'], '</td>';
        foreach ($timeslots as $slot) {
            echo '<td>';
            if (signed_up_for_this_slot) { display_name }
            else {
                echo '<a href="signup.php?day=', $day['id'],
                     '&activity=', $activity['id'], '&time=', $slot['id'], '">Signup!</a>';
            }
            echo '</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
}

Re: PHP sign-up table

Posted: Mon Jul 13, 2009 4:51 pm
by smccoy4
Thank you very much. I have it working with the help that you gave me earlier. You can see what I have now if you would like. http://sts.indstate.edu/~smccoy4/oittent/index.php

user: oittent pw: oittent

The only thing I don't have working is when I select the box on the new version, Instead of going to a different page I would like the pop-up that I have to allow them to enter their name and hit submit. but I keep getting a login error. Oh well, this one is just me messing around now trying to learn some new things. Thanks for your help again!

Re: PHP sign-up table

Posted: Thu Jul 16, 2009 4:04 pm
by smccoy4
Ok guys, apparently there is a major glitch somewhere in my code. For some reason, the first person to sign up, regardless of where they signup will also have their name copied to Tuesday Information1 4:00-7:30 timeslot. However, the duplicate post is not saved to the database and if I manually put a person in at that time they will not show up. It appears as though the persons name is being hardcoded into the page.

Also, I am unable to get the login page to work correctly. I have tried a session variable, but I am afraid that I may be doing it wrong. I am going to try and place a link with the code to my reply so that you can see my entire code and give me tips to maybe improve upon what I have or help me fix what is wrong?

http://sts.indstate.edu/~smccoy4/oittent_code.html

Re: PHP sign-up table

Posted: Mon Jul 20, 2009 8:11 am
by smccoy4
Ok, I think I may be close. I am still convinced that there is an easier way to do it. Here is the code for one of the, supposedly, easier tables. The rest of the tables actually have multiple columns and rows. But I am sure that once I am able to get this, it will be much easier to figure out the rest. Problem is when it prints to screen it prints a lot of extra rows. Please help!

Code: Select all

 
<table align="center" frame="border" width="330" height="31" border ="1" bordercolor="blue">
<caption style="font-weight=bold" span class="style1">Set-up and Break-down Crew</caption>
<tr>
    <td align="center"><b>Saturday-Tuesday</b><br/>
        <b>9:30-10:00 & 4:00-4:30</b></td>
</tr>
<?php
include("dbcon.php");
$setup_array = mysql_query("SELECT * from tent group by time") or die(mysql_error());
 
while($row = mysql_fetch_array($setup_array))
{
    $name = $row['name'];
    $activity = $row['activity'];
    $time = $row['time'];
    $days = $row['day'];
$t = 4;
$i = 0;
while($i<=5)
{
    if($time == $t)
    {
        $array_setup[$i] = "<tr><td align='center'>".$name."</td></tr>";
        echo $array_setup[$i];
        $i++;
        $t++;
    }
    else
    {
        $array_setup[$i] = "<tr><td align='center'><a href='signup.php?day=4&activity=11&time=".$t."'><img border='0' src='images/signup.gif'></a></td></tr>";
        echo $array_setup[$i];
        $i++;
        $t++;
    }
}
}
?>
</table>