首先,我需要透露我在这里是一个主要的菜鸟......但我想我会变得更好! (在很大程度上要归功于堆栈溢出社区的帮助:-D)
我为项目里程碑创建了一个动态生成的菜单。它使用一个表,允许用户输入每个里程碑的日期和描述,并将它们保存到数据库中。每次用户想要输入新里程碑时,他们都会单击按钮以动态生成新行。 (见图片说明:https://dl.dropboxusercontent.com/u/11993667/milestones_ex.png注意:复选框仅用于立即删除行)
到目前为止一切都很好。问题是,一旦用户保存他们的里程碑,我希望他们能够重新访问该页面并修改他们的里程碑或添加更多。显然,这需要脚本查询数据库并相应地生成/填充行。
我拼凑了以下代码以从数据库生成表单但由于某种原因它崩溃了页面。我检查了错误日志,并注意到相关似乎出现了。我想知道是否有人可能会看到我所拥有的或者能够推荐替代方法的明显错误。如果它有帮助,我写这个是作为wordpress的插件部署。
非常感谢任何帮助。
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 */
答案 0 :(得分:0)
您的脚本中存在语法错误:
foreach ($months as $month) {
if($month == $milestone->month){
echo <<<EOHTML
<option value="{$month}" selected>$month</option>
EOHTML;
continue:
^ This should be ; and not :
}
echo <<<EOHTML
<option value="{$month}">$month</option>
EOHTML;
}