php - 未选择数据库

标签 php mysql database twitter-bootstrap

我在分页表中显示 mysql 数据时遇到问题。使用 Bootstrap 框架。希望有人能帮助我解决这件事。

我使用 MAMP 并在 mysql 中创建了 2 个具有以下名称的数据库:

  1. Bootstrap
  2. 数据

在 htdocs 中创建 2 个不同的文件夹,名称如下:

  1. 库存<---用于数据数据库(用于库存)
  2. 系统<---用于 Bootstrap 数据库(用于用户ID)

首先,我将所有文件放在同一个文件夹中,但出现错误 - 未选择数据库。检查mysql,权限已经默认为全局。结果如下图:

http://i58.tinypic.com/rll6jc.png

然后,当我使用不同的文件夹时,我得到“未选择数据库”

用数据填充两个数据库中的表.. 不知道为什么数据没有显示在index.php中..

谢谢磨坊!!~

<小时/>

index.php 文件

    <?php

include('Inventory/includes/config.php');

$per_page = 5;
$adjacents = 5; 

$pages_query = mysql_query("SELECT COUNT(id), item, brand, model, qty FROM invdata") or die(mysql_error());

//get total number of pages to be shown from  total result
$pages = ceil(mysql_result($pages_query, 0) / $per_page);

//get current page from URL ,if not present set it to 1
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1 ;

//calculate actual start page with respect to Mysql 
$start = ($page - 1) * $per_page;

//execute a mysql query to retrieve  all result from current page by using LIMIT keyword in mysql
//if  query  fails stop further execution and show mysql error

$query = mysql_query("SELECT id, item, brand, model, qty FROM invdata LIMIT $start, $per_page") or die(mysql_error());

$pagination="Pagination";
//if current page is first show first only else reduce 1 by current page
$Prev_Page = ($page==1)?1:$page - 1;

//if current page is last show last  only else add  1 to  current page
$Next_Page = ($page>=$pages)?$page:$page + 1; 

//if we are not on first page show first link
if($page!=1) $pagination.= '<a href="?page=1">First</a>';
//if we are not on first page show previous link
if($page!=1) $pagination.='<a href="?page='.$Prev_Page.'">Previous</a>';

//we are going to display 5 links on pagination bar
$numberoflinks=5;

//find the number of links to show on right of current page
$upage=ceil(($page)/$numberoflinks)*$numberoflinks;
//find the number of links to show on left of current page
$lpage=floor(($page)/$numberoflinks)*$numberoflinks;
//if  number of links on left of current page are zero we start from 1
$lpage=($lpage==0)?1:$lpage;
//find the number of links to show on right of current page and make sure it must be less than total number of pages
$upage=($lpage==$upage)?$upage+$numberoflinks:$upage;
if($upage>$pages)$upage=($pages-1);
//start building links from left to right of current page
for($x=$lpage; $x<=$upage; $x++){
//if current building link is current page we don't show link,we show as text else we show as linkn 
$pagination.=($x == $page) ? ' <strong>'.$x.'</strong>' : ' <a href="?page='.$x.'">'.$x.'</a>' ;
}
//we show next link and last link if user doesn't on last page
if($page!=$pages) $pagination.=  '  <a href="?page='.$Next_Page.'">Next</a>';
if($page!=$pages) $pagination.=  ' <a href="?page='.$pages.'">Last</a>';


?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Test 2</title>
<link href="Inventory/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container-fluid">
<div class="table-responsive">
  <table class="table">
    <tr>
    <th>ITEM</th>
    <th>BRAND</th>
    <th>MODEL</th>
    <th>QUANTITY</th>
    </tr>
    <?php
    while($row = mysql_fetch_array($query))
    {
    $f1 = $row['item'];
    $f1 = $row['brand'];
    $f1 = $row['model'];
    $f1 = $row['qty'];
    ?>
    <tr>
    <td><?php echo $f1 ?></td>
    <td><?php echo $f2 ?></td>
    <td><?php echo $f3 ?></td>
    <td><?php echo $f4 ?></td>
    </tr>
    <?php
    } //while
    ?>
  </table>
</div>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="Inventory/js/bootstrap.min.js"></script>

</body>

</html>
<小时/>

config.php 文件

    <?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "data";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password, or die ("Connection error");
mysql_select_db($mysql_database, $bd) or die ("Database error");
?>

最佳答案

更改此行

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password, or die ("Connection error");

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die ("Connection error");

我建议您使用 mysqli_* 而不是 mysql_* ,因为 mysql_* 现已弃用。

希望这对您有帮助。

关于php - 未选择数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30296560/

相关文章:

PHP 从 gridview 编辑行

java - 如何在 Digital Ocean Nginx VPS 上运行 Java 代码?

php - MySQL-多连接

mysql - 在 Monit 中使用 --login-path 检查脚本给出错误 1045 (28000)

php - Laravel Eloquent 将 3 个查询合二为一

php - 如何将json数据保存到mysql?

mysql - utf-8 与 latin1

php - 按特定值获取 JSON 数据

php - 无法连接到 MySQL 服务器(2006 错误)

php - 在包含 HTML 的文档上使用差异