Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Displaying data linked from two MySQL Tables

    Okay, I have two tables. One being Reviews:
    Code:
    CREATE TABLE `reviews` (
     `ID` int(11) NOT NULL AUTO_INCREMENT,
     `GameID` varchar(80) NOT NULL,
     `MemberID` int(11) NOT NULL,
     `Enviroment` double NOT NULL,
     `Enviro-Review` text NOT NULL,
     `Controls` double NOT NULL,
     `Controls-Review` text NOT NULL,
     `Gameplay` double NOT NULL,
     `Gameplay-Review` text NOT NULL,
     `Entertainment` double NOT NULL,
     `Entertain-Review` text NOT NULL,
     `Replayability` double NOT NULL,
     `Replay-Review` text NOT NULL,
     `Date` date NOT NULL,
     PRIMARY KEY (`ID`),
     UNIQUE KEY `ID` (`ID`)
    ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1
    The other being members:
    Code:
    CREATE TABLE `members` (
     `ID` int(11) NOT NULL AUTO_INCREMENT,
     `Name` varchar(80) NOT NULL,
     `Md5` text NOT NULL,
     `Email` varchar(80) NOT NULL,
     `Admin` int(1) NOT NULL DEFAULT '0',
     PRIMARY KEY (`ID`),
     UNIQUE KEY `ID` (`ID`),
     UNIQUE KEY `Name` (`Name`)
    ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
    I am wanting to display all 'reviews' and also display the members name from the reviews.MemberID in PHP.

    How would this be done?
    Last edited by EffakT; 04-23-2013 at 04:13 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Thats a simple join:
    Code:
    SELECT r.*, m.Name
    FROM reviews r
    INNER JOIN members m ON m.ID = r.MemberID
    Where r.* should be each field you want and not wildcarded. Pump that through mysqli or PDO and iterate the records to get all the resultsets.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Apr 2012
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks, I knew it was a join, just didn't know what type.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •