Jump to content


Photo

n00b help - pulling two sql tables


  • Please log in to reply
1 reply to this topic

#1 bleemster

bleemster
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 13 February 2018 - 09:49 AM

I seem to be having trouble pulling in information from two tables...

 

I can get all the info from the data table and display it in tables but how to i replace the code as shown with xxxxxxxxx with the FULLNAME field from the USER table which is associated with the USERNAME or $_SESSION Username?

 

Thanks in advanced

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

session_start();
if(!isset($_SESSION['username'])){
  header("Location:login.php");
}
require('connect.php');

// create query
$query = "SELECT * FROM data WHERE CREATOR='xxxxxxxxx' AND AVAILABILITY > 0 ORDER BY ID DESC";
$query2 = "SELECT * FROM user";
$query3 = "SELECT * FROM data WHERE CREATOR LIKE 'xxxxxxxxxx' AND AVAILABILITY = 0 ORDER BY ID DESC LIMIT 10";

// get results
$result = mysqli_query($connection, $query);
$result2 = mysqli_query($connection, $query2);
$result3 = mysqli_query($connection, $query3);

// Fetch data
$data = mysqli_fetch_all($result, MYSQLI_ASSOC);
$user = mysqli_fetch_all($result2, MYSQLI_ASSOC);
$data2 = mysqli_fetch_all($result3, MYSQLI_ASSOC);

// var_dump($user);
// free result
mysqli_free_result($result);
mysqli_free_result($result2);
mysqli_free_result($result3);

// Close Connection
mysqli_close($connection);
?>


Edited by bleemster, 13 February 2018 - 09:56 AM.


#2 phpmillion

phpmillion
  • Members
  • PipPipPip
  • Advanced Member
  • 76 posts
  • LocationLithuania

Posted 13 February 2018 - 11:00 AM

Most likely you are looking for MySQL JOIN functionality. https://www.w3school...ql/sql_join.asp






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users