douyi1963 2018-07-06 21:03 采纳率: 0%
浏览 57

php navbar(bootstrap)链接到包含页面的特定选项卡

I've searched and searched and found many similar questions but i haven't found anything that has worked.

i am trying to write a simple php crud page where i have an index.php page using nav-tabs (drop down menus as i will add more pages after getting these to work)

i have a drop down menu that links to a vendorlanding.php page which displays a grid and simple add/update/delete links.

i can successfully navigate to this page from index.php but when i click on any of the links from vendorlanding.php (ie add a new vendor: addvendor.php) nothing happens.

i would like it to open the addvendor.php page in the current tab.

any help is greatly appreciated

below is contents of index.php and vendorlanding.php

index.php:

<?php
// Initialize the session
session_start();
 
// If session variable is not set it will redirect to login page
if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
  header("location: login.php");
  exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test Ledger</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
$("#myTab a").click(function(e){
    e.preventDefault();
    $(this).tab('show');
});
});
</script>

<style type="text/css">
.bs-example
    {
        width: 55%;
        padding-left: 15%;
      }        
    .header 
    {
        width: 55%;
        padding-left: 15%;
    }
    .footer 
    {
        width: 55%;
        padding-left: 15%;
    }
    .padding2 
    {
        margin: 100px;
        padding-left: 50%;
        margin: 100px;
    }
    body{ font: 14px sans-serif; }

</style>
</head>
<body>

<div class = "header"> 
  <h2>welcome <b><?php echo htmlspecialchars($_SESSION['username']); ?></b>. <a href="logout.php" class="btn btn-danger btn-sm">Sign Out</a>  
  </br>
  </br>
</div>
</br>
</br>

<div class="bs-example">
    <ul class="nav nav-tabs" id="myTab">
        <li class="active"><a data-toggle="tab" href="#Home">Home</a></li>                        
        <li class="dropdown">
            <a data-toggle="dropdown" class="dropdown-toggle" href="#">Ledger Content<b class="caret"></b></a>
            <ul class="dropdown-menu">                                
                <li><a data-toggle="tab" href="#viewvendors">View Vendors</a></li>                                
            </ul>
        </li>
        <li class="dropdown">
            <a data-toggle="dropdown" class="dropdown-toggle" href="#">Manage Users<b class="caret"></b></a>
            <ul class="dropdown-menu">                
                <li><a data-toggle="tab" href="#adduser">Add User</a></li>            
            </ul>
        </li>
    </ul>
    
    <div class="tab-content">
        <div id="Home" class="tab-pane fade in active">
              <?php
                include("main.inc.php");
            ?>
        </div>        
        <div id="viewvendorslanding" class="tab-pane fade">
            <?php
               include("vendorLanding.php");
             ?>
        </div>        
        <div id="adduser" class="tab-pane fade">
         <?php
            include("register.php");
         ?>
        </div>
        <div id="addvendor" class="tab-pane fade">
         <?php
            include("addVendor.php");
         ?>
        </div>
    </div>
</div>
</br>
</br>
</br>
<div class="footer">
  <?php
    include("footer.inc.php");
  ?>
</div>
</body>
</html>                            

vendorlanding.php --> this has a button to add a new vendor (which doesn't work)

    <body>
        <div class="wrapper1">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="page-header clearfix">
                            <h2 class="pull-left">Vendor Details</h2>
                            <a href="index.php#addvendor" class="btn btn-success pull-right">Add New Vendor</a>

                         
                        </div>

                        <?php

                        // Include config file

                        require_once '../dbConfig.php';

                        

                        // Attempt select query execution

                        $sql = "SELECT * FROM vendors";

                        if($result = mysqli_query($link, $sql)){

                            if(mysqli_num_rows($result) > 0){

                                echo "<table class='table table-bordered table-striped'>";

                                    echo "<thead>";

                                        echo "<tr>";

                                            echo "<th>#</th>";

                                            echo "<th>Name</th>";

                                            echo "<th>Description</th>";                                            

                                        echo "</tr>";

                                    echo "</thead>";

                                    echo "<tbody>";

                                    while($row = mysqli_fetch_array($result)){

                                        echo "<tr>";

                                            echo "<td>" . $row['vendor_id'] . "</td>";

                                            echo "<td>" . $row['vendor_name'] . "</td>";

                                            echo "<td>" . $row['vendor_description'] . "</td>";                                            

                                            echo "<td>";

                                                echo "<a href='vendorRead.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";

                                                echo "<a href='vendorUpdate.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";

                                                echo "<a href='vendorDelete.php?id=". $row['id'] ."' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";

                                            echo "</td>";

                                        echo "</tr>";

                                    }

                                    echo "</tbody>";                            

                                echo "</table>";

                                // Free result set

                                mysqli_free_result($result);

                            } else{

                                echo "<p class='lead'><em>No records were found.</em></p>";

                            }

                        } else{

                            echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);

                        }

     

                        // Close connection

                        //mysqli_close($link);

                        ?>

                    </div>

                </div>        

            </div>

        </div>

    </body>

    </html>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看