Jump to content

Putting a function amongs an echo.


Siggles

Recommended Posts

Hi, I have a script that updates and removes gigs from a MySQL dbase. Amongst the code that adds the gig (and is called using, for example ?nav=addnews) I have a function defined that displays some <select> tags for the day, month and year so people can specify a date. I then call that function amongst a long echo command that prints lots of html. Instead of the drop down boxes appearing amongst the form they appear at the top of the page (where the function is defined I think). What i am doing wrong? Thank you for your help.

 

$addnews="

 

<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">

 

...............

..............

td align=\"left\" >".DateSelector("Sample")."</td></tr>

Link to comment
Share on other sites

This is the function. Works fine, just is in wrong place.

 

<?php

 

/****************************************/

/*Function:DateSelector v1.1 */

/*Code: PHP 3          */

/*Author: Leon Atkinson <leon@clearink.com> */

/*Creates three form fields for get month/day/year */

/*Input: Prefix to name of field, default date */

/*Output: HTML to define three date fields */

/****************************************/

 

function DateSelector($inName, $useDate=0)

{

/* create array so we can name months */

$monthName = array(1=> "January", "February", "March",

"April", "May", "June", "July", "August",

"September", "October", "November", "December");

 

/* if date invalid or not supplied, use current time */

if($useDate == 0)

{

$useDate = Time();

}

 

/* make month selector */

echo "<SELECT NAME=" . $inName . "Month>\n";

for($currentMonth = 1; $currentMonth <= 12; $currentMonth++)

{

echo "<OPTION VALUE=\"";

echo intval($currentMonth);

echo "\"";

if(intval(date( "m", $useDate))==$currentMonth)

{

echo " SELECTED";

}

echo ">" . $monthName[$currentMonth] . "\n";

}

echo "</SELECT>";

 

/* make day selector */

echo "<SELECT NAME=" . $inName . "Day>\n";

for($currentDay=1; $currentDay <= 31; $currentDay++)

{

echo "<OPTION VALUE=\"$currentDay\"";

if(intval(date( "d", $useDate))==$currentDay)

{

echo " SELECTED";

}

echo ">$currentDay\n";

}

echo "</SELECT>";

 

/* make year selector */

echo "<SELECT NAME=" . $inName . "Year>\n";

$startYear = date( "Y", $useDate);

for($currentYear = $startYear - 1; $currentYear <= $startYear+3;$currentYear++)

{

echo "<OPTION VALUE=\"$currentYear\"";

if(date( "Y", $useDate)==$currentYear)

{

echo " SELECTED";

}

echo ">$currentYear\n";

}

echo "</SELECT>";

 

}

 

/****************************************/

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.