我目前正在制作一个基于 PHP 和 mySQL 的时间表网站,我遇到了一个问题,我会在具有多个条件的表中提取多个数据,这里有一些代码:
$db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$uid = $_SESSION['user_id'];
$data_query = "SELECT users.user_name, jobs.job_code, jobs.job_desc, jobs.job_client, jobs.job_year, jobs.job_month, jobs.job_category, job_taker.job_hours ".
"FROM jobs,job_taker,users ".
"WHERE 'login.jobs.job_id' = 'login.job_taker.job_id' AND 'login.users.user_id' = ('.$uid.')".
"ORDER BY 'login.jobs.job_id' DESC";
$data_result = mysqli_query($db_connection,$data_query) or die(mysql_error());
这是我将显示结果的地方:
<?php
while($info = mysqli_fetch_array($data_result)) {
?>
<tr>
<td> <input type="checkbox" name="<?php echo $info['job_code']?>" id="<?php echo $info['job_code']?>" value="<?php echo $info['job_code']?>" /></td>
<td><?php echo $info['user_name'] ?></td>
<td><?php echo $info['job_code'] ?> </td>
<td><?php echo $info['job_client'] ?> </td>
<td><?php echo $info['job_year'] ?> </td>
<td><?php echo $info['job_month']?> </td>
<td><?php echo $info['job_date']?> </td>
<td><?php echo $info['job_category']?> </td>
</tr>
<?php } ?>
这是我数据库中的 SQL 转储:
CREATE TABLE IF NOT EXISTS `jobs` (
`job_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`job_code` varchar(32) NOT NULL,
`job_desc` varchar(500) NOT NULL,
`job_client` varchar(500) NOT NULL,
`job_year` int(11) NOT NULL,
`job_month` int(11) NOT NULL,
`job_date` int(11) NOT NULL,
`job_category` varchar(25) NOT NULL,
PRIMARY KEY (`job_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `job_taker` (
`user_id` bigint(20) unsigned NOT NULL,
`job_id` int(11) unsigned NOT NULL,
`job_hours` int(11) unsigned NOT NULL,
PRIMARY KEY (`user_id`,`job_id`),
KEY `user_id` (`user_id`),
KEY `user_id_2` (`user_id`),
KEY `job_id` (`job_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `users` (
`user_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'auto incrementing user_id of each user, unique index',
`user_name` varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'user''s name',
`user_position` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`user_status` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`user_password_hash` char(60) COLLATE utf8_unicode_ci NOT NULL COMMENT 'user''s password in salted and hashed format',
`user_email` varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'user''s email',
`user_active` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'user''s activation status',
`user_activation_hash` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'user''s email verification hash string',
`user_password_reset_hash` char(40) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'user''s password reset code',
`user_password_reset_timestamp` bigint(20) DEFAULT NULL COMMENT 'timestamp of the password reset request',
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name` (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='user data' AUTO_INCREMENT=8 ;
ALTER TABLE `job_taker`
ADD CONSTRAINT `job_taker_ibfk_2` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`job_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `job_taker_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
我的问题是,当我试图打开显示它的页面时,它根本没有显示任何数据。它没有给出任何 SQL 语法错误,只是简单的空白数据页。
这是我尝试的结果echo $data_result
Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\seclog\views\user_edit_job.php on line 11
有没有什么办法解决这一问题?
感谢任何试图帮助或阅读本文的人!