这里我有我的代码,当我测试它一切正在工作很好的床边那个 MySQL连接的结果没有显示。我尝试了不同的东西但似乎没有任何效果我希望有人在这里找到并引用导致此数据库不起作用的问题。
这是我的代码
<!DOCTYPE html>
<html lang="en">
<head>
<title>Senior Projects Portal | Senior Advisors</title>
<link rel="icon" href="logo.ico" type="image/x-icon">
<link rel="shortcut icon" href="logo.ico" type="image/x-icon" />
<meta name="description" content="Senior Project Portal">
<meta name="keywords" content="Senior Project Portal">
<meta name="author" content="Mr">
<meta charset="UTF-8">
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/modern-business.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.php">Senior Projects Portal</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="index.php">Home</a>
</li>
<li class="active">
<a href="advisor.php">Senior Advisors</a>
</li>
<li>
<a href="pro-search.php">Search Projects</a>
</li>
<li>
<a href="project.php">Choose Project Topic</a>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<img class="img-responsive" src="img/user.png" style="width:22px; height:20px; "alt="">
</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<!-- Page Heading/Breadcrumbs -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">List
<small>of Senior Advisors</small>
</h1>
<ol class="breadcrumb">
<li><a href="index.php">Home</a>
</li>
<li class="active">Senior Advisors</li>
</ol>
</div>
</div>
<!-- /.row -->
<!-- Content Row -->
<div class="row">
<div class="col-lg-12">
<?php
$cn=mysql_connect("localhost","aalkaabi","leatkifs") or die
(mysql_error());
mysql_select_db("aalkaabi",$cn) or die(mysql_error());
$sql = "SELECT * FROM aalkaabi.Supervisor";
$rs = mysql_query($sql) or die(mysql_error());
$no=1;
?>
<?
while($row = mysql_fetch_array($rs)){?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#<? echo $no?>"><? echo $row["0"]?></a>
</h4>
</div>
<div id="<? echo $no?>" class="panel-collapse collapse">
<div class="panel-body">
<h3><? echo $row["0"]?></h3>
<p>
<? echo $row["1"]?><br>
</p>
<p><i class="fa fa-envelope-o"></i>
<abbr title="Email"><b>Email</abbr>:</b> <a href="mailto:<? echo $row["3"]?>"><?phpecho $row["2"]?></a>
</p>
<p><i class="fa fa-phone"></i>
<abbr title="Phone"><b>Phone</abbr>:</b> <?echo $row["3"]?></p>
<p><i class="fa fa-clock-o"></i>
<abbr title="Courses Taught"><b>Courses Taught</b></abbr>: <? echo $row["4"]?></p>
</div>
</div>
</div>
<!-- /.panel -->
<?
$no = $no + 1;
}mysql_free_result($rs);
?>
</div>
<!-- /.panel-group -->
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<hr>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © <b style="color:#428bca;">Senior Projects Portal</b>, 2015.</p>
</div>
</div>
</footer>
</div>
<!-- /.container -->
<!-- jQuery Version 1.11.0 -->
<script src="js/jquery-1.11.0.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
答案 0 :(得分:0)
至少更新到mySqli:也找到了错误
$rs = mysqli_query($sql) or die(mysqli_error());
应该是
$rs = mysqli_query($cn, $sql) or die(mysqli_error());
以及其余代码:
<?php
$cn=mysqli_connect("localhost","aalkaabi","leatkifs") or die (mysqli_error());
mysqli_select_db("aalkaabi",$cn) or die(mysqli_error());
$sql = "SELECT * FROM aalkaabi.Supervisor";
$rs = mysqli_query($cn, $sql) or die(mysqli_error());
$no=1;
while($row = mysqli_fetch_array($rs)){?>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#<? echo $no; ?>"><? echo $row[0]; ?></a>
</h4>
</div>
<div id="<? echo $no; ?>" class="panel-collapse collapse">
<div class="panel-body">
<h3><? echo $row[0]; ?></h3>
<p><? echo $row[1]; ?><br></p>
<p><i class="fa fa-envelope-o"></i>
<abbr title="Email"><b>Email</abbr>:</b> <a href="mailto:<? echo $row[3]; ?>"><?phpecho $row[2]; ?></a>
</p>
<p><i class="fa fa-phone"></i>
<abbr title="Phone"><b>Phone</abbr>:</b> <?echo $row[3]; ?></p>
<p><i class="fa fa-clock-o"></i>
<abbr title="Courses Taught"><b>Courses Taught</b></abbr>: <? echo $row[4]; ?></p>
</div>
</div>
</div>
</div>
<?
$no = $no++;
}
mysqli_free_result($rs);
?>