Jump to content

[SOLVED] help with variable or funciton


dadamssg

Recommended Posts

i want to put the code below in a variable or function or whatever so i can call it into my template without writing the entire thing...any help?

 

<?php
/*  Program name: dateSelect.php
*  Description:  Program displays a selection list that
*                customers can use to select a date.
*/
echo "<html>
       <head><title>Select a date</title></head>
       <body>";

$smonth = array(1=> "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun", "Jul",
                        "Aug", "Sep", "Oct",
                        "Nov", "Dec");

$today = time();                   //stores today's date
$f_today = date("M-d-Y",$today);   //formats today's date

echo "<div style = 'text-align: center'>\n";


/* create form containing date selection list */
echo "<form action='processform.php' method='POST'>\n";

/* build selection list for the month */
$todayMO = date("n",$today);  //get the month from $today
echo "<select name='dateMO'>\n";
for ($n=1;$n<=12;$n++) 
{
   echo "<option value=$n\n";
   if ($todayMO == $n)
   {
     echo " selected";
   }
   echo "> $smonth[$n]\n";
}
echo "</select>";

/* build selection list for the day */
$todayDay= date("d",$today);    //get the day from $today
echo "<select name='dateDay'>\n";
for ($sday=1;$sday<=31;$sday++)  
{
   echo " <option value=$sday";
   if ($todayDay == $sday ) 
   {
     echo " selected";
   }
   echo "> $sday\n";
}
echo "</select>\n";

/* build selection list for the year */
$startYr = date("Y", $today);  //get the year from $today
echo "<select name='dateYr'>\n";
for ($syear=$startYr;$syear<=$startYr+1;$syear++)
{
   echo " <option value=$syear";
   if ($startYr == $syear )
   {
     echo " selected";
   }
   echo "> $syear\n";
}
echo "</select>\n";

echo "</form>\n";
?>
</body></html>

Link to comment
https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/
Share on other sites

<?php
/*  Program name: dateSelect.php
*  Description:  Program displays a selection list that
*                customers can use to select a date.
*/
function echoList() {
echo "<html>
       <head><title>Select a date</title></head>
       <body>";

$smonth = array(1=> "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun", "Jul",
                        "Aug", "Sep", "Oct",
                        "Nov", "Dec");

$today = time();                   //stores today's date
$f_today = date("M-d-Y",$today);   //formats today's date

echo "<div style = 'text-align: center'>\n";


/* create form containing date selection list */
echo "<form action='processform.php' method='POST'>\n";

/* build selection list for the month */
$todayMO = date("n",$today);  //get the month from $today
echo "<select name='dateMO'>\n";
for ($n=1;$n<=12;$n++) 
{
   echo "<option value=$n\n";
   if ($todayMO == $n)
   {
     echo " selected";
   }
   echo "> $smonth[$n]\n";
}
echo "</select>";

/* build selection list for the day */
$todayDay= date("d",$today);    //get the day from $today
echo "<select name='dateDay'>\n";
for ($sday=1;$sday<=31;$sday++)  
{
   echo " <option value=$sday";
   if ($todayDay == $sday ) 
   {
     echo " selected";
   }
   echo "> $sday\n";
}
echo "</select>\n";

/* build selection list for the year */
$startYr = date("Y", $today);  //get the year from $today
echo "<select name='dateYr'>\n";
for ($syear=$startYr;$syear<=$startYr+1;$syear++)
{
   echo " <option value=$syear";
   if ($startYr == $syear )
   {
     echo " selected";
   }
   echo "> $syear\n";
}
echo "</select>\n";

echo "</form>\n";
}

echoList(); // usage.
?>

ok heres what i got....the first code is sdateselectfun.inc which contains my function and the second is my html table....but when i call the function..its just outputs a blank cell...help please

 

<?php
/*  Program name: dateSelectfun.inc
*  Description:  Program displays a selection list that
*                customers can use to select a date.
*/
function sdateselect() {
echo "
       

$smonth = array(1=> "Jan", "Feb", "Mar",
                        "Apr", "May", "Jun", "Jul",
                        "Aug", "Sep", "Oct",
                        "Nov", "Dec");

$today = time();                   //stores today's date
$f_today = date("M-d-Y",$today);   //formats today's date




/* create form containing date selection list */

/* build selection list for the month */
$todayMO = date("n",$today);  //get the month from $today
echo "<select name='dateMO'>\n";
for ($n=1;$n<=12;$n++) 
{
   echo "<option value=$n\n";
   if ($todayMO == $n)
   {
     echo " selected";
   }
   echo "> $smonth[$n]\n";
}
echo "</select>";

/* build selection list for the day */
$todayDay= date("d",$today);    //get the day from $today
echo "<select name='dateDay'>\n";
for ($sday=1;$sday<=31;$sday++)  
{
   echo " <option value=$sday";
   if ($todayDay == $sday ) 
   {
     echo " selected";
   }
   echo "> $sday\n";
}
echo "</select>\n";

/* build selection list for the year */
$startYr = date("Y", $today);  //get the year from $today
echo "<select name='dateYr'>\n";
for ($syear=$startYr;$syear<=$startYr+1;$syear++)
{
   echo " <option value=$syear";
   if ($startYr == $syear )
   {
     echo " selected";
   }
   echo "> $syear\n";
}
echo "</select>\n";


}
?>

 

<?php

/*File: testdisplay.inc
*Display test form
*/
include("sdateselectfun.inc");

?>


<html>
<head><title>Event Post Form</title></head>
<body>
<br><br><center><h2><b>Event Post Form</b></h2></center>


<?php
if (isset($message))
    {
     echo "<center><Font color=red><b>$message</b></font></center>";
    }
?>

<center>
<form action="checkpost.php" method="POST">
<Table border='7'>
<tr>
<td><center><b>Title:&nbsp</b></center></td>
<td><input type="text" name="title" size="75" maxsize="75"></td>
</tr>
<tr>
<td valign="top"><br><b>&nbspDescription:&nbsp</b></td>
<td><textarea name='description' cols='57' rows='5'>
</textarea></td>
</tr>
<tr>
<td>Starts:&nbsp</td><td align=center><?php sdateselect(); ?></td>
</tr>
<tr>
<td><center><b>Event Type:&nbsp</b></center></td>
<td><select name='event'> 
                                <option value='Music'>Music
                                   <option value='Sports'>Sports
                                     <option value='Shows'>Shows
                                        <option value='LocalFestivs'>LocalFestivs
                                          <option value='other'>Other</select>
</td>
</tr>
<input type="hidden" name="do" value="Submit">
<tr>
<td colspan='2' align="center">
<input type="submit" name="do" value="Submit">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

because he is including the wrong file maybe?

he has an s infront of the file name and an uncapitalised letter in the include path.

 

If that was the case a fatal error would display, however he may have errors turned off, but yea. I do not know how he is really naming that file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.