I'm trying to join three tables from a database in-order to display a users selected categories but I get the following error.
Warning: mysqli_error() expects exactly 1 parameter, 0 given in
I think I'm doing something wrong when I query my database.
Here is the code below.
// Query member data from the database and ready it for display
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT users.*, categories.*, users_categories.* FROM users_categories INNER JOIN users_categories ON users_categories.user_id = users.user_id JOIN categories ON users_categories.user_id = users.user_id WHERE users_categories.user_id=3");
if (!$dbc) {
// There was an error...do something about it here...
print mysqli_error();
}
//Users entered category loop
while ($row = mysqli_fetch_assoc($dbc)) {
if (! empty($row['category'])) {
echo '<div class="skill-info">';
echo '<p>' , htmlspecialchars($row['category']) , '</p>';
}
}
Here is my MySQL tables structure.
CREATE TABLE users (
user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_name VARCHAR(255) NOT NULL,
PRIMARY KEY (user_id)
);
CREATE TABLE categories (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
parent_id INT UNSIGNED NOT NULL DEFAULT 0,
category VARCHAR(255) NOT NULL,
url VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
INDEX parent (parent_id)
);
CREATE TABLE users_categories (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL,
category_id INT UNSIGNED NOT NULL,
PRIMARY KEY (id)
);
Now I get the following error
Not unique table/alias: 'users_categories'
How do I fix this?
Thanks everyone for the help. Is there a way i can reward every one for there help here on stackoverflow instead of one person?