2017-10-27 1 views
0

나는 wordpress에서 function.php를 수정했고 단축키를 사용하여 wordpress 메뉴에서 PHP 페이지를 호출했습니다. 나는 연결할 수 있고 PHP 페이지를 표시 할 수 있습니다. PHP 페이지에서 드롭 다운 목록에서 값을 선택하지 않고 모든 레코드를 초기에 표시 할 수 있습니다. 그러나 드롭 다운 목록에 따라 필터링 된 레코드를 표시하는 대신 드롭 다운 목록에서 값을 변경하면 페이지가 WordPress 인덱스 페이지로 이동합니다. 나는 그것이 php 페이지에 머 무르지 않고 submit 명령으로 onaction 명령을 의심한다. 대신 wordpress index 페이지로 간다.wordpress에서 PHP 페이지 호출

<?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&nbsp&nbsp</a> 
     </tr> 
     <?php } ?> 
    </table> 

</body> 
</html> 
+0

사용자가 드롭 다운을 변경할 때마다 카테고리 페이지로 리디렉션하려고합니까? – June

+0

이 부분을 변경하려고 시도 : action = "" –

+0

드롭 다운 값이 변경되고 그에 따라 세부 레코드가 필터링 될 때마다 동일한 PHP 페이지로 보내고 싶습니다. 웹 사이트 kkits.in-> services-> IT courses에서 확인할 수 있습니다 – yesganesh

답변

0

짧은 코드의 사용은 필수 사항입니까? 페이지를 만들지 않는 이유는 무엇입니까? 슬러그 .php, 하위 테마를 통해 재정의하고 표준 permalink 기능을 통해 리디렉션과 URL을 가져 오는 것은 어떨까요?

관련 문제