php - MySQL Table JOIN Advice -


i wondering best advise approach couple of points. have working database able register new users, create call documents , categories. tables set out following:

users tables     `id` int(11) not null,       `username` text not null,       `password` varchar(64) not null,       `psalt` text not null   documents table `doc_id` int(11) not null,   `doc_title` varchar(50) not null,   `doc_content` text not null,   `doc_created` datetime not null,   `doc_updated` timestamp not null default current_timestamp  categories table `cat_id` int(11) not null,   `cat_title` varchar(32) not null 

so when login 1 user admin - 2 tables join , need table join them? little unclear on how these become related tried using tool relate them in phpmyadmin (not best tool have work with). reason behind because if logged in 'admin' or user , create doc want published user.

also, in regards documents, belong category. not sure association is. end result there number of users can see different categories , depending on category docs see.

so, going advice have managed filter through data , make show sql.

select user_login.id,user_login.username, doc_list.doc_title user_login, doc_list user_login.id=user_id 

i have added new column in doc_list table called 'user_id' , relation published it. now, manually entered user_id fields make sure got results back, how php (see below) going push user id table automated?

<?php  if(isset($_post["submit"])){ $hostname='localhost'; $username='######'; $password='######';  try {  $dbh = new pdo("mysql:host=$hostname;dbname=######",$username,$password);  $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); // <== add line  $sql = "insert doc_list (doc_title, doc_content, doc_created) values ('".$_post["doc_title"]."','".$_post["doc_content"]."', now() )";   if ($dbh->query($sql)) {     header ('location: ../doclist.php'); } else{ }  $dbh = null; } catch(pdoexception $e) { echo $e->getmessage(); }  } ?> 

you need put user-id belongs users table in documents table provide "it published user" , join users tables documents table.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -