First I need to disclose that I’m a major noob here…but I think I’m getting better! (in no small part thanks to the help of the stack overflow community :-D)
I’ve created a dynamically generated menu for project milestones. It uses a table that allows the user to enter the date and description of each milestone and save them to a database. Each time the user wants to enter a new milestone, they click a button to dynamically generate a new row. (See picture for clarification: https://dl.dropboxusercontent.com/u/11993667/milestones_ex.png Note: the checkboxes are only used to delete rows right now)
That all works great so far. The issue is that once the user saves their milestones, I want them to be able to revisit the page and modify their milestones or add more. Obviously this requires the script to query the database and generate/populate the rows accordingly.
I cobbled together the following code to generate the form from the database but for some reason it crashes the page. I’ve checked the error log and noting relevant seems to turn up. I was wondering if anyone might see a glaring error with what I’ve got or be able to recommend an alternative method. In case it helps, I’m writing this to be deployed as a plugin for wordpress.
Any help is much appreciated.
function upsmart_create_milestones_form() {
global $wpdb;
$data = $wpdb->get_results($wpdb->prepare("SELECT * FROM upsmart_milestones WHERE wordpress_id=%d",get_current_user_id()),ARRAY_A);
$months = array('January','February','March','April','May','June','July ','August','September','October','November','December');
echo <<<EOHTML
<form method='post'>
<h3>Project Milestones</h3>
<script type="text/javascript" src="http://upsmart.com/wp-content/plugins/upsmart_sitemanager/js/create_business_milestone.js"></script>
<input type="button" value="Add Row" onclick="addRow('dataTable')" />
<input type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<table id="dataTable" width="350px" border="1">
EOHTML;
foreach($data as $milestone){
echo <<<EOHTML
<tr>
<td><input type="checkbox" name="chk[]"/></td>
<td>
<select name="month[]">
EOHTML;
foreach ($months as $month) {
if($month == $milestone->month){
echo <<<EOHTML
<option value="{$month}" selected>$month</option>
EOHTML;
continue;
}
echo <<<EOHTML
<option value="{$month}">$month</option>
EOHTML;
}
echo <<<EOHTML
</select>
<select name="day[]">
EOHTML;
foreach (range(1, 31) as $day) {
if($month == $milestone->day){
echo <<<EOHTML
<option value="{$day}" selected>$day</option>
EOHTML;
}
echo <<<EOHTML
<option value="{$day}">{$day}</option>
EOHTML;
}
echo <<<EOHTML
</select>
<select name="year[]">
EOHTML;
foreach (range(2013, 1990, -1) as $year) {
if($month == $milestone->year){
echo <<<EOHTML
<option value="{$year}" selected>$year</option>
EOHTML;
}
echo <<<EOHTML
<option value="{$year}">{$year}</option>
EOHTML;
}
echo <<<EOHTML
</select>
</td>
<td> <input type="text" name="txt[]"/>$milestone->description</td>
</tr>
EOHTML;
} /* END FOR EACH LOOP ON MILESTONES */
echo <<<EOHTML
</table>
<input type='submit' value='Save'/>
</form>
EOHTML;
}/* END FUNCTION */
You have a syntax error in your script: