このコードでは、クエリから内部結合を削除すると、すべて正常に動作します。また、phpMyAdmin からのクエリを試してみましたが、問題なく動作しました。
これが私のコードです:
$db = mysql_connect("localhost", USERNAME,PASSWORD);
if (!$db) {
echo("<p>Error creating Database Connection</p>");
exit;
}
$db_selected = mysql_select_db(DATABASE_NAMEPH,$db);
$sql = "SELECT * FROM user " +
"INNER JOIN gender ON user.id = gender.user_id "+
"INNER JOIN user_address ON user.id = user_address.user_id "+
"INNER JOIN address ON address.id = user_address.address_id;";
$result = mysql_query($sql,$db);
if(!$result){
echo( "<p>Unable to query database at this time.</p>" );
}
$num_results = mysql_num_rows($result);
mysql_close($db);
while( $row = mysql_fetch_assoc($result)){
echo" <form name='register' class='register'> ";
echo" <fieldset class='row1'>";
echo" <legend>".$row["fName"].", ".$row["lName"]."'s Personal Details</legend> </fieldset>";
echo" <p><label>Email:</label><data> ".$row["email"]."</data> </p>";
echo" <p><label>First Name:</label><data> ".$row["fName"]."</data></p>";
echo" <p><label>Last Name:</label><data> ".$row["lName"]."</data></p>";
echo" <p><label>Phone:</label><data> ".$row["phone"]."</data></p>";
echo" <p><label>Street:</label><data> ".$row["street"]."</data></p>";
echo" <p><label>City:</label><data> ".$row["city"]."</data></p>";
echo" <p><label>State: </label><data>".$row["state"]."</data></p>";
echo" <p><label>Zip Code:</label><data> ".$row["zip"]."</data></p>";
echo" <p><label>Gender:</label><data> ".$row["name"]."</data></p>";
echo" <p><label>Birthdate:</label><data> ".$row["bDate"]."</data></p>";
echo" <p><label>Additional Info:</label><data> ".$row["info"]."</data></p>";
echo" <p><label>Admin:</label><data> ".$row["flag"]."</data></p></fieldset></form>";
}
?>
<h3 id="path">Number of users registered: <?php echo $num_results; ?></h3>
これが私が得るエラーメッセージです:
Unable to query database at this time.
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in
/Users/mjramahi/Sites/web/admin/users.php on line 129
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in
/Users/mjramahi/Sites/web/admin/users.php on line 132