我在wordpress中修改了function.php,并使用短代码从wordpress菜单调用了php页面。我能够连接并显示php页面。 在php页面中能够显示所有记录而无需从下拉列表中选择值。但是当我更改下拉列表中的值而不是根据下拉列表显示已过滤的记录时,页面将转到wordpress索引页面。我怀疑onaction命令作为一个提交它不停留在被调用的php页面而不是它转到wordpress索引页面。
<?php
$selected = '';
function get_options($select) {
$categories = ['Select Category' => 0, 'Information Technology' => 1, 'Management' => 2];
$options = '';
while (list($k, $v) = each($categories)) {
if ($select == $v) {
$options .= '<option value="' . $v . '" selected>' . $k . '</option>';
} else {
$options .= '<option value="' . $v . '" >' . $k . '</option>';
}
}
//var_dump($options);
//echo var_dump($options)."<br>";
return $options;
}
require_once('dbconnect.php');
if (isset($_POST['categories'])) {
$selected = $_POST['categories'];
echo $selected;
}
if ($selected == 1) {
$selectedcat = 'Information Technology';
$selectsql = "SELECT * FROM courses where ccategory='$selectedcat'";
} else if ($selected == 2) {
$selectedcat = 'Management';
$selectsql = "SELECT * FROM courses where ccategory='$selectedcat'";
} else {
$selectsql = "SELECT * FROM courses";
}
//require_once('dbconnect.php');
//include('header-basic-light.php');
//$selectsql="SELECT * FROM courses";
$res = (mysqli_query($con, $selectsql));
if (!mysqli_query($con, $selectsql)) {
die(mysqli_error($con));
}
mysqli_close($con);
//header('Location:index.php');
?>
<HTML>
<head>
//<title>"View Information"</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="categories">Select the Category : </label>
<select name="categories" style="width:250px;" onchange="this.form.submit();">
<?php echo get_options($selected); ?>
</select>
</form>
<h2>View Information</h2>
<table class="table">
<tr>
<th>#</th>
<th>cname</th>
<th>start_date</th>
<th>duration</th>
<th>Remarks</th>
<th>Options</th>
</tr>
<?php
while ($r = mysqli_fetch_assoc($res)) {
?>
<tr>
<td><?php echo $r['cno']; ?></td>
<td><?php echo $r['cname']; ?></td>
<td><?php echo $r['start_date']; ?></td>
<td><?php echo $r['duration']; ?></td>
<td><?php echo $r['remarks']; ?></td>
<?php if ($r['ccategory'] == 'Information Technology') {
$catnum = 1;
}
if ($r['ccategory'] == 'Management') {
$catnum = 2;
} ?>
<td><a href="loadpage.php?id=<?php echo $catnum; ?>">Details  </a>
</tr>
<?php } ?>
</table>
</body>
</html>
答案 0 :(得分:0)
使用短代码是必需的吗?为什么不创建一个page- slug .php,通过子主题覆盖它并通过标准的永久链接函数获取重定向和URL?