我遇到了一个奇怪的mysql错误。通过以下文本,我得到:Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /Applications/XAMPP/xamppfiles/htdocs/chatterr/lr_bootstrap/profile.php on line 70
尽管代码没有任何问题。我尝试die("Error in query: ".mysql_error());
在上面添加,if (mysql_num_rows($check_frnd_query) == 1 OR $user_id == $my_id) {
但没有返回任何内容。我被这个问题所困扰。我可能正在查看一些东西。你怎么看?
<?php
ob_start();
include 'core/init.php';
include 'includes/overall/overall_header.php';
if (isset($_GET['username']) === true && empty($_GET['username']) === false) {
$username = $_GET['username'];
if (user_exists($username) === true) {
$my_id = $session_user_id;
$user_id = user_id_from_username($username);
$profile_data = user_data($user_id, 'username', 'first_name', 'last_name', 'email', 'profile_img', 'bio');
$user = $user_id;
?>
<div class="container-fluid">
<div class="row-fluid">
<?php include 'includes/sidebar.php'; ?>
<div class="span9">
<div class="hero-unit">
<p>
<?php
if (empty($profile_data['profile_img']) === false) {
echo '<img src="', $profile_data['profile_img'],'" alt="', $profile_data['first_name'] ,'\'s Profile Image" class="profile">';
}
?></p>
<h2><?php echo $profile_data['first_name'],' ', $profile_data['last_name']; ?> </h2>
<p><?php echo $profile_data['bio']?></p>
<p>
<?php if($user_id === $session_user_id) {
?> <a href="settings.php">Edit Profile</a> <?php
} else {
if (logged_in() === true) {
if($user != $my_id){
$check_frnd_query = mysql_query("SELECT id FROM friends WHERE (user_one ='$my_id' AND user_two='$user') OR (user_one='$user' AND user_two='$my_id')");
if (mysql_num_rows($check_frnd_query) == 1) {
echo "Friends | <a href='actions.php? action=unfriend&user=$user' class='box'>Unfriend $username</a>";
} else {
$from_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$user' AND `to`='$my_id'");
$to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to`='$user'");
if(mysql_num_rows($from_query) == 1) {
echo "<a href='actions.php? action=accept&user=$user' class='box'>Accept</a> | <a href='actions.php?action=ingnore&user=$user' class='box'>Ignore</a>";
} else if (mysql_num_rows($to_query) == 1) {
echo "<a href='actions.php?action=cancel&user=$user' class='box'>Cancel Request</a>";
} else {
echo "<a href='actions.php? action=send&user=$user' class='box'>Send Friend Request </a>";
}
}
}
} //logged in
} ?>
<!-- If friends:
<a>My Photos</a>
<a>My Friends</a>
<a>Message Me</a>
</p>
-->
<!--<p><a href="#" class="btn btn-primary btn-large">My Profile »</a></p> -- >
</div>
<div class="row-fluid">
<?php
if (mysql_num_rows($check_frnd_query) == 1 OR $user_id == $my_id) {
$res=mysql_query("SELECT * FROM posts WHERE user_id=$user_id ORDER BY timestamp DESC LIMIT 0, 3");
while($row=mysql_fetch_assoc($res)) {
?>
<div class="span4">
<h2><?php echo $profile_data['first_name']?> said...</h2>
<h8><?php echo $row['timestamp']; ?></h8>
<p><?php echo $row['content']; ?></p>
<p><a class="btn" href="#">View Reactions »</a></p>
</div><!--/span-->
<?php
}
?>
</div><!--/row-->
<div class="row-fluid">
<?php
$res=mysql_query("SELECT * FROM posts WHERE user_id=$user_id ORDER BY timestamp DESC LIMIT 3, 6");
while($row=mysql_fetch_assoc($res)) {
?>
<div class="span4">
<h2><?php echo $profile_data['first_name']?> said...</h2>
<h8><?php echo $row['timestamp']; ?></h8>
<p><?php echo $row['content']; ?></p>
<p><a class="btn" href="#">View Reactions »</a></p>
</div><!--/span-->
<?php
}
?>
</div><!--/row-->
</div><!--/span-->
</div><!--/row-->
<?php
} else {
echo '<h3>Whoops, you must be friends with this user to see their posts.</h3>';
}
} else {
header('Location: 404.php');
exit();
}
} else {
header('Location: index.php');
exit();
}
include'includes/overall/overall_footer.php';
?>
这就是我所看到的:http: //pbrd.co/Zo6sNb