html - Get foreign key with php (syntax) -


i have 2 tables

create table comment(     commenttext text,     commentdate date not null,     time time,     postedby varchar(30),     foreign key (postedby) references employee(name) );  create table employee(  name varchar(30),  title varchar(30),  onshift boolean,  primary key(name) ); 

now how can following

$comments =     mysql_query("select * comment"); $all_comments = array(); while($row = mysql_fetch_array($comments)) {     $all_comments[] = $row; }  foreach($all_comments $commentrow){     if($commentrow['postedby']){ //check if employee onshift          echo("the employee on shift");     }     else{         echo("the employee on shift");     } } 

i.e given foreign key (postedby) lookup value in foregin keys table (in case if boolean if staff on shift?)

your select should like

select c.*, e.name, e.onshift comment c join employee e on c.postedby = e.name 

and can use

$commentrow['onshift'] 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -