dadamssg Posted January 18, 2009 Share Posted January 18, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/ Share on other sites More sharing options...
premiso Posted January 18, 2009 Share Posted January 18, 2009 <?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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740017 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 i think i love you...thanks Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740022 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 but if im gonna put his in an html table, do i need to delete the <html><head><body> tags? Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740027 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 Of course. Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740029 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 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: </b></center></td> <td><input type="text" name="title" size="75" maxsize="75"></td> </tr> <tr> <td valign="top"><br><b> Description: </b></td> <td><textarea name='description' cols='57' rows='5'> </textarea></td> </tr> <tr> <td>Starts: </td><td align=center><?php sdateselect(); ?></td> </tr> <tr> <td><center><b>Event Type: </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> Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740044 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 Remove the.... echo " line (2nd line in the function). Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740049 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 still blank...ive never been able to call a function thats stored in another file...this is frustrating Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740054 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 You need to name the file with the php extension, not inc. Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740055 Share on other sites More sharing options...
Flames Posted January 18, 2009 Share Posted January 18, 2009 on textdisplay.inc change the first bit to <?php /*File: testdisplay.inc *Display test form */ include("dateSelectfun.inc"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740056 Share on other sites More sharing options...
premiso Posted January 18, 2009 Share Posted January 18, 2009 I would stray away from .inc and do .inc.php instead to hide your code. As far as why it does not work, no clue. Tested something similar on my system and it worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740057 Share on other sites More sharing options...
Flames Posted January 18, 2009 Share Posted January 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740059 Share on other sites More sharing options...
premiso Posted January 18, 2009 Share Posted January 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740060 Share on other sites More sharing options...
dadamssg Posted January 18, 2009 Author Share Posted January 18, 2009 FINALLY! :) that was the problem...i changed both the testdisplay.inc to testdisplay.php and the sdateselectfun.inc to dateselectfun.inc to .php too, yall are awesome thanks! Quote Link to comment https://forums.phpfreaks.com/topic/141379-solved-help-with-variable-or-funciton/#findComment-740061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.