programmierfrage.com
Ask a question    Sign Up Sign In
  • Train typing speed
  • About/Contact
  • Privacy Policy
  1. Home
  2. php - MySQL join another table value based on 2 different tables matching value?

385 votes
2 answers

php - MySQL join another table value based on 2 different tables matching value?

Get the solution ↓↓↓
Closed. This question needs details or clarity. It is not currently accepting answers.

Undefined asked
2021-12-6
Write your answer



852
votes

Answer

Solution:

Your query looks quite fine. You would just need to qualify columnuser_id in thefrom clause with the table it belongs to:

SELECT j.price, p.profilepic
FROM Jobs j
INNER JOIN Offers o  ON o.job_id = j.job_id
INNER JOIN Profile p ON o.user_id = p.user_id
WHERE p.user_id = ?  -- or j.user_id = ?
Write your answer




291
votes

Answer

Solution:

MySQL doesn't like that you have two identical columns nameduserid. So simply choose one for the where clause

$sql="SELECT
       j.price,
      p.profilepic
      FROM Jobs j
      INNER JOIN Offers o  ON o.job_id = j.job_id
      INNER JOIN Profile p ON o.user_id = p.user_id
      WHERE j.user_id=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i",$_SESSION['user_id']);
$stmt->execute();
$stmt->bind_result($price,$profilepic);
$stmt->fetch();

See example https://www.db-fiddle.com/f/wUqVKNZy96RjR7hTk3md7o/6

Write your answer




Share solution ↓

Additional Information:

Date the issue was resolved:
2021-12-6
Link To Source
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered in

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

839 PHP select from MySQL tables and save in another table
483 php - MySQL update column with value from second table
215 mysqli - How to solve mysqli_fetch_array() expects parameter 1 to be mysqli_result,string in php
769 mysql - php Multiple Key Value Filter with an or statement
228 PHP array merge values from one array into another
796 php - Insert specific value on first $key in array
212 Using PHP have a MySQL statement into multiple PHP variables
414 PHP function to get needed values form array
417 php - 1366 Incorrect decimal value Laravel
606 php - Empty values inserted to database

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.






About the technologies asked in this question

PHP

PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/


MySQL

DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL. It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/



Welcome to programmierfrage.com

programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

Get answers to specific questions

Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

Help Others Solve Their Issues

Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.



Latest questions:

584 php - converting from mysql to PDO username confirmation issue

958 php - Using Faker in Laravel 5.0 returns 'Class User not found'

726 javascript - How to display returned json using jquery ajax

882 Eclipse PDT PHP + HTML Formatter is not aligned?

356 Issue with filtering down MySQL database with internal search PHP

717 html - How to insert a link before php variable

593 PHP script not writing data to mysql table

329 php - MySQL update column with value from second table

310 javascript - symfony2 advanced select in form

726 php - Python subprocess doesn't recognize commands in $PATH

Users questions:

NEW

Rename existing images with keyword in WordPress PHP

NEW

codeigniter

NEW

Class "web_profiler.controller.profiler" does not exist after upgrading symfony 3.4 to 4.4 version

NEW

$charge = \Stripe\Charge::create(array( "amount" => 100, "currency" => "gbp", "source" => $token, "destination" => [ "amount" => 20, "account" => 'xxxxx', ], ));

NEW

Write a PHP program that will generate the JSON structure below. Second Step: Write a JAVASCRIPT program that will parse the JSON structure once the PHP program is called using AJAX. You may show your output on the body of the HTML document or in the console




PHP x 410847
Laravel x 36785
Yii x 3846
CodeIgniter x 9997
Symfony x 7793
CakePHP x 3085
Zend Framework x 1235
Phalcon x 300
FuelPHP x 47
Slim x 570
JavaScript x 36883
React x 550
Angular x 1121
Vue.js x 181
JQuery x 11108
Backbone.js x 21
Node.js x 463
Ember.js x 10
Meteor x 7
Polymer x 20
Aurelia x 1
MySQL x 39074
CSS x 2497
Bootstrap x 1603
Foundation x 84
UIkit x 4
Semantic UI x 2
Bulma x 2
Animate.css x 1
HTML x 20978



© 2021-2023 Programming problem solving site for beginners and advanced. Answers to questions related to coding.

E-mail: [email protected]

This site uses cookies. We use them to improve the performance of our website and your interaction with it. Confirm your consent by clicking OK


OK