我正在撰写一个网站,用户可以在其中查看彼此的个人资料和待售产品。我的配置文件部分已完成,并且一直有效,直到我尝试集成产品部分。它似乎破坏了整个网站。
我想要实现的目标是从数据库中获取产品并将其显示在网格中,其中包含上传产品用户名和产品说明的用户。最终,我将在产品图片下对产品进行5星评价,但这不是在这里,也不在那里。
我使用与用户网格和数据库相同的代码,但它没有按预期工作。
我的产品页码是:
<?php
include 'controllers/grid/products-grid.php';
?>
产品网格页面是:
<?php include 'components/authentication.php' ?>
<?php include 'controllers/base/head.php' ?>
<?php include 'controllers/navigation/first-navigation.php' ?>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="row clearfix">
<?php
include '_database/database.php';
session_start();
$current_user = $_SESSION['user_username'];
$sql = "SELECT * FROM user WHERE product_id != '$product_id' order by product_id desc";
$result = mysqli_query($database,$sql) or die(mysqli_error($database));
while($rws = mysqli_fetch_array($result)){
?>
<div class="col-md-4 column">
<div class="panel-group" id="panel-<?php echo $rws['product_id']; ?>">
<div class="panel panel-default">
<div id="panel-element-<?php echo $rws['user_id']; ?>" class="panel-collapse collapse in">
<div class="panel-body">
<div class="col-md-6 column">
<img src="products/<?php echo $rws['user_avatar'];?>" name="products" class="img-responsive"> </div>
<div class="col-md-6 column">
<h2><span><a href="product.php?product_id=<?php echo $rws['product_name'];?>"><? php echo $rws['user_username'];?> <?php echo $rws['product_description'];?></a> </span></h2>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
我的产品sql页面是:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `mydb`
--
CREATE DATABASE IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `mydb`;
-- --------------------------------------------------------
--
-- Table structure for table `products`
--
DROP TABLE IF EXISTS `products`;
CREATE TABLE IF NOT EXISTS `products` (
`user_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL AUTO_INCREMENT,
`user_firstname` text NOT NULL,
`user_lastname` text NOT NULL,
`user_username` varchar(255) NOT NULL,
`product_name` varchar(60) NOT NULL,
`product_desc` tinytext NOT NULL,
`product_img_name` varchar(60) NOT NULL,
`price` decimal(10,2) NOT NULL,
`size` varchar(60) NOT NULL,
UNIQUE KEY `product_id` (`product_id`)
) AUTO_INCREMENT=1 ;
-- Dumping data for table `follow`
--
INSERT INTO `products` (`user_id`, `product_id`, `user_firstname`, `user_lastname`, `user_username`, `product_name`, `product_desc`, `product_img_name`) VALUES
(1, '1', 'MyFirstname', 'MyLastname', 'myusername', 'product1' ,'a product by me', 'product1');
ALTER TABLE `products`
ADD UNIQUE KEY (`product_id`), ADD UNIQUE KEY `product_name` (`product_name`), ADD UNIQUE KEY `product_img_name` (`product_img_name`), ADD UNIQUE KEY `user_username` (`user_username`);
我的用户数据sql文件是:
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `mydb`
--
CREATE DATABASE IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `mydb`;
-- --------------------------------------------------------
--
-- Table structure for table `follow`
--
DROP TABLE IF EXISTS `follow`;
CREATE TABLE IF NOT EXISTS `follow` (
`follow_id` int(11) NOT NULL,
`follow_current_user` varchar(255) NOT NULL,
`follow_profile_user` varchar(255) NOT NULL,
`follow_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;
--
-- Dumping data for table `follow`
--
INSERT INTO `follow` (`follow_id`, `follow_current_user`, `follow_profile_user`, `follow_timestamp`) VALUES
(13, 'User13', 'Surname', '2015-10-10 03:09:58'),
(15, 'User15', 'Surname', '2015-11-10 03:33:43'),
(16, 'User16', 'Surname', '2015-11-210 03:41:58');
-- --------------------------------------------------------
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
CREATE TABLE IF NOT EXISTS `user` (
`user_id` int(11) NOT NULL,
`user_email` varchar(255) NOT NULL,
`user_password` varchar(255) NOT NULL,
`user_firstname` text NOT NULL,
`user_lastname` text NOT NULL,
`user_avatar` varchar(255) NOT NULL,
`user_shortbio` text,
`user_username` varchar(255) NOT NULL,
`user_longbio` text,
`user_dob` date DEFAULT NULL,
`user_profession` text,
`user_gender` varchar(255) DEFAULT NULL,
`user_maritialstatus` varchar(255) DEFAULT NULL,
`user_address` text,
`user_backgroundpicture` varchar(255) NOT NULL,
`user_joindate` date NOT NULL,
`user_country` varchar(255) DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ;
--
-- Dumping data for table `user`
--
INSERT INTO `user` (`user_id`, `user_email`, `user_password`, `user_firstname`, `user_lastname`, `user_avatar`, `user_shortbio`, `user_username`, `user_longbio`, `user_dob`, `user_profession`, `user_gender`, `user_address`, `user_backgroundpicture`, `user_joindate`, `user_country`) VALUES
(1, 'me@gmail.com', 'password', 'firstname', 'Surname', 'default.jpg', 'Lorem ipsum dolor sit amet', 'Firstname', 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit', '1916-08-08', 'Student', 'Male', NULL, 'default.jpg', '2015-11-11', 'countryland');
-- --------------------------------------------------------
--
-- Table structure for table `view`
--
DROP TABLE IF EXISTS `view`;
CREATE TABLE IF NOT EXISTS `view` (
`view_id` int(11) NOT NULL,
`view_profile_user` varchar(255) NOT NULL,
`view_current_user` varchar(255) NOT NULL,
`view_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=123 ;
--
-- Dumping data for table `view`
--
INSERT INTO `view` (`view_id`, `view_profile_user`, `view_current_user`, `view_timestamp`) VALUES
(65, 'blub', 'blubsworth', '2015-10-18 19:30:56');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `follow`
--
ALTER TABLE `follow`
ADD PRIMARY KEY (`follow_id`);
--
-- Indexes for table `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`user_id`), ADD UNIQUE KEY `user_email` (`user_email`), ADD UNIQUE KEY `user_username` (`user_username`);
--
-- Indexes for table `view`
--
ALTER TABLE `view`
ADD PRIMARY KEY (`view_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `follow`
--
ALTER TABLE `follow`
MODIFY `follow_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=17;
--
-- AUTO_INCREMENT for table `user`
--
ALTER TABLE `user`
MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=18;
--
-- AUTO_INCREMENT for table `view`
--
ALTER TABLE `view`
MODIFY `view_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=123;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;