Page 1 of 1
Form to go with my html
Posted: Fri Dec 10, 2004 1:16 pm
by chadbobb
I got some help here a while ago and i got this below. I added a little bit to it to make it work with tables and stuff. But for some reason i can't get form to show up in wher i want them to. I keep getting an error that says
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/warren/public_html/whs/form template3.php on line 20
What do i need to just get a text box in one of those and a text area box?
thanks
Code: Select all
<table border="1" width="100%">
<FORM METHOD="POST" ACTION="mailto:your email address">
<tr>
<td width="25%">Date</td>
<td width=25% valign="top"> </td>
<td width="50%">Assignment</td>
</tr>
<?php
$days=5;
function futureday($num_days_future)
{ for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
{
$numsec = 86400 * $x; //Multiply seconds by num_days_future
$nextday = time()+ $numsec; //Get Unix Time stamp
echo "<tr><td>" . date("j of F Y", $nextday) . "</td><td>I want a Form here</td><td>I want another form here</td></tr>";
}
}
futureday($days);
?>
Posted: Fri Dec 10, 2004 2:03 pm
by rehfeld
if you want it to ouput some html there, just cut and paste the html in that location
you can echo over multiple lines like so
echo "
blah
blah
";
your parse error is likely because you did not escape double quotes like so
Code: Select all
echo "<form method="post">"; // parse error
echo "<form method="post">"; // correct, or use next method
echo '<form method="post">'; // works, notice using single quotes
// you can also drop out of php
function futureday($num_days_future)
{ for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
{
$numsec = 86400 * $x; //Multiply seconds by num_days_future
$nextday = time()+ $numsec; //Get Unix Time stamp
echo "<tr><td>" . date("j of F Y", $nextday);
?>
</td><td>I want a Form here</td><td>I want another form here</td></tr>
quotes dont matter if we drop out of php, because its directly output w/out parsing
<?php
}
}
Posted: Sun Dec 12, 2004 1:15 am
by chadbobb
whoa. I think i kinda understood what you just said, but im still a php newb.
i figured out what you were saying.
Now i need help with something else, lol
I got help with the time stuff of it also a while back. what i want to do is also be able to go into negative days. Is there anyway i can do that without heavily moddifying it? i notice when i put in a negative sign that it will not go into the past like i want it to. How can i make it show stuff days from lets say 13 days ago?
Code: Select all
<html>
<table border="1" width="100%">
<FORM METHOD="POST" ACTION="mailto:your email address">
<tr>
<td width="25%">Date</td>
<td width=25% valign="top"> </td>
<td width="50%">Assignment</td>
</tr>
<?php
$days=-21;
function futureday($num_days_future)
{ for ($x=0; $x<$num_days_future; $x++)// loop through and add one day in seconds each time...
{
$numsec = 86400 * $x; //Multiply seconds by num_days_future
$nextday = time()+ $numsec; //Get Unix Time stamp
echo "<tr><td>" . date("j of F Y", $nextday) . "</td><td><INPUT TYPE="text" NAME="name" SIZE="30"></td><td><TEXTAREA NAME="comment" ROWS=2 valign="top" COLS="40"></TEXTAREA></td></tr>";
}
}
futureday($days);
?>
</table>
</html>
BTW thanks a bunch for the help
Posted: Sun Dec 12, 2004 2:50 am
by Bennettman
The reason it's not showing the negative days, is because of the first argument in the for loop:
syntax: for ( command at start of loop; condition check; command after every loop )
So, you're setting $x to 0, then checking that $x is less than -21 (which it's not).
I'd say, to do it right, change the function to have two arguments, one for the start date and one for the end date (both in days compared to the present), and use the start date to set $x at the start of the loop:
Code: Select all
<?php
$start = -21; // 21 days ago
$end = 14; // 14 days ahead
function days($start, $end) {
for ($x = $start; $x <= $end; $x++) {
$numsec = 86400 * $x; // Get the current time offset in seconds
$nextday = time() + $numsec; // Get Unix timestamp
echo '<tr><td>' . date("j of F Y", $nextday) . '</td><td><INPUT TYPE="text" NAME="name" SIZE="30"></td><td><TEXTAREA NAME="comment" ROWS=2 valign="top" COLS="40"></TEXTAREA></td></tr>';
}
}
days($start, $end); // call the function
?>
That said, if you're not planning on running the function more that once in order to get more than one get of rows etc (I doubt it), you don't need the function - you can just take out the function definition and the call, and just have the for loop.