这是我到目前为止所得到的:
global $wpdb;
$sql = "SELECT Cause FROM `wp_test` WHERE Accepted = 1 ORDER BY Name";
$res = $wpdb->get_results($sql);
echo "<select name = 'venue'>";
while (($row = mysql_fetch_row($res)) != null)
{
echo "<option value = '{$row[???]}'";
if ($selected_venue_id == $row[???])
echo "selected = 'selected'";
echo ">{$row['???']}</option>";
}
echo "</select>";
while循环之前的代码有效。如何使while循环返回我的列?
答案 0 :(得分:0)
如果您的查询为WPDB
课程,则不需要使用mysql_*
家庭功能,所有工作都由此课程完成,您只需要循环$res
它包含查询返回的数据
global $wpdb;
$sql = "SELECT Cause FROM `wp_test` WHERE Accepted = 1 ORDER BY Name";
$res = $wpdb->get_results($sql);
if (!empty($res)) {
echo "<select name = 'venue'>";
foreach ($res as $key => $val) {
echo "<option value = '" . $val->Cause . "'";
if ($selected_venue_id == $val->Cause)
echo "selected = 'selected'";
echo ">" . $val->Cause . "</option>";
}
echo "</select>";
}