Show related text not id

New to all this and just playing so would appreciate your time.

I have set up a simple database with relationships to the data I need also set up.
I have a webpage setup also that shows me all the data from the table but the relationships show as the id.
I would like to show a different column from the relationship not the id.

Can anyone help?

Thanks

We don’t have a crystal ball. Post your code.

Sorry, code below.
projects_customer related to customer table
projects_architect related to suppliers table
projects_structural_engineer related to suppliers table

I can get the id to show on the page but would like to show these three columns but as the name not the id.

Thanks

[php]

<title>Starter Template for Bootstrap</title>

<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="css/starter-template.css" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="js/ie-emulation-modes-warning.js"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<?php $servername = "localhost"; $username = "root"; $password = ""; try { $conn = new PDO("mysql:host=$servername;dbname=belmore", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="http://localhost/belmore/"><strong>Belmore</strong></a>
    </div>
    <div id="navbar" class="collapse navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="http://localhost/belmore/">Home</a></li>
        <li><a href="">About</a></li>
        <li><a href="">Contact</a></li>
      </ul>
    </div><!--/.nav-collapse -->
  </div>
</nav>

<div class="container">

  <div class="starter-template">
    <h1>Projects</h1>
      </div>

</div><!-- /.container -->
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "belmore"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }

$sql = “SELECT * FROM projects”;

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row

} else {
echo “0 results”;
}

mysqli_close($conn);
?>

          <tr>
           
            <th>ID</th>
            <th>Project Name</th>
            <th>Project Number</th>       
          </tr>
        </thead>
        <tbody>
				<?php					
					while($row = mysqli_fetch_assoc($result))								
					{
					
					echo '<tr>
						<td><a href="projectteam.php?id='.$row['projects_id'].'">'.$row['projects_id'].'</a></td>
						<td>'.$row['projects_name'].'</td>
						<td>'.$row['projects_number'].'</td>
			</tr>';
						
					}
				?>
        </tbody>
      </table>
    </div>


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
[/php]

Putting you code in tags will also help… :wink:

Anyways, why are you using PDO and mysqli at the same time?

Are you have a problem with PHP or HTML/CSS?

You need to do a JOIN on the tables.
https://dev.mysql.com/doc/refman/5.7/en/join.html

Sponsor our Newsletter | Privacy Policy | Terms of Service