PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] phpmyadmin - How to set field values dependant on foreign key?

 January 23, 2022     database, mysql, phpmyadmin, sql-server     No comments   

Issue

How do I setup fields to be dependent on what foreign key is input?

I have googled and searched stack overflow, using similar questions to that, but couldn't find anything that fitted what I was looking for. There are pictures and an example below to better describe what I am asking.

Here's my table (that I want fields to be dependant on there foreign keys): enter image description here

jo_route is a foreign key for this table: enter image description here

and jo_type is a foreign key for this table: enter image description here enter image description here

When I go to insert a record into the journeys table, and select the route id. How do I get the corresponding information from that foreign keys table to appear in the respective fields in this table.

For example, jo_type as 3 records (as shown in the picture). The foreign key jo_type is linked with this table. Say I select the ID for air (2) in the journeys table. How do I get the related fields (jo_seats_total) to be automatically chosen from the travel types table? So it should appear as 100.

Hopefully I have explained my problem well enough.

Thanks in advance for any help! Sorry for the long post.


Solution

I hope this is something that you looking for...

SELECT t.tt_max_seat, t.tt_name, r.ro_origin, r.ro_destination, 
j.jo_seats_total, j.jo_seats_take, j.jo_seats_available
FROM journey j
JOIN route r ON j.jo_route = r.ro_id
JOIN type t ON j.jo_type = t.tt_id
WHERE j.jo_type = 2


Answered By - Naincy
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing