How to connect 2 tables from the same database?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I made a mini system to upload photos as profile and cover, but when I put the two includes 1 if it works and the other does not work when putting the other include. If anyone knows help me please



the 2 are from the same base but different tables, what I want is to connect the 2 tables so that they work without any error



I am new at this






====table 1==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_banner` ";
$ res = mysqli_query ($ cn, $ sql);
?>

====table 2==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_profile` ";
$ res = mysqli_query ($ cn, $ sql);
?>












share|improve this question























  • Why are you using include() to the same file twice? Also don't use the same variable names for your database query $sql = > $res you are over writing them. Use different ones and see if you get data from both tables.

    – NewToJS
    Nov 23 '18 at 1:50








  • 1





    You can do all of this in SQL (and should - it is made for this stuff!). Once you have that, then come use the SQL statement in PHP code. You want to read up on relations between tables, primary keys, foreign keys, sub-selects, and joins.

    – ivanivan
    Nov 23 '18 at 1:57











  • @ivanivan What do you mean "You can do all of this in SQL" The Op is using php to make a SQL Database connection and query.... What does this have to do with primary keys? The OP wants to create a database connection (which is done) but then execute a query to get all data from two tables.... The problem is using duplicate variable names which is causing a over write of the first one or so I believe.... If I am wrong please explain as this will be helpful to me too, thank you.

    – NewToJS
    Nov 23 '18 at 2:03













  • @NewToJS if there is a relationship between the data then you can select table1.column, table2.column where table1.othercol=table2.othercol. Or you can use joins. Or you can subselect. SQL is incredibly powerful, and if you are wanting to "connect two tables together" and there is any kind of relationship to the data they contain then do it in SQL. Without seeing the OPs actual database structure and a sample of desired output (or use), I can't give him a good SQL statement. Now if the data is totally unrelated, then yes, the solution of using 2 different vars for results is the thing.

    – ivanivan
    Nov 23 '18 at 2:17








  • 1





    @ivanivan I understand what you mean and completely agree. Without knowing the structure of the tables and if a relation of the two exist it is hard to offer a solution. I wasn't clear on your suggestion based on the first comment but with more detail I understand where you are going with your suggestion. I think we need more information before being able to offer anything more than the suggestions given so far.

    – NewToJS
    Nov 23 '18 at 2:28


















0















I made a mini system to upload photos as profile and cover, but when I put the two includes 1 if it works and the other does not work when putting the other include. If anyone knows help me please



the 2 are from the same base but different tables, what I want is to connect the 2 tables so that they work without any error



I am new at this






====table 1==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_banner` ";
$ res = mysqli_query ($ cn, $ sql);
?>

====table 2==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_profile` ";
$ res = mysqli_query ($ cn, $ sql);
?>












share|improve this question























  • Why are you using include() to the same file twice? Also don't use the same variable names for your database query $sql = > $res you are over writing them. Use different ones and see if you get data from both tables.

    – NewToJS
    Nov 23 '18 at 1:50








  • 1





    You can do all of this in SQL (and should - it is made for this stuff!). Once you have that, then come use the SQL statement in PHP code. You want to read up on relations between tables, primary keys, foreign keys, sub-selects, and joins.

    – ivanivan
    Nov 23 '18 at 1:57











  • @ivanivan What do you mean "You can do all of this in SQL" The Op is using php to make a SQL Database connection and query.... What does this have to do with primary keys? The OP wants to create a database connection (which is done) but then execute a query to get all data from two tables.... The problem is using duplicate variable names which is causing a over write of the first one or so I believe.... If I am wrong please explain as this will be helpful to me too, thank you.

    – NewToJS
    Nov 23 '18 at 2:03













  • @NewToJS if there is a relationship between the data then you can select table1.column, table2.column where table1.othercol=table2.othercol. Or you can use joins. Or you can subselect. SQL is incredibly powerful, and if you are wanting to "connect two tables together" and there is any kind of relationship to the data they contain then do it in SQL. Without seeing the OPs actual database structure and a sample of desired output (or use), I can't give him a good SQL statement. Now if the data is totally unrelated, then yes, the solution of using 2 different vars for results is the thing.

    – ivanivan
    Nov 23 '18 at 2:17








  • 1





    @ivanivan I understand what you mean and completely agree. Without knowing the structure of the tables and if a relation of the two exist it is hard to offer a solution. I wasn't clear on your suggestion based on the first comment but with more detail I understand where you are going with your suggestion. I think we need more information before being able to offer anything more than the suggestions given so far.

    – NewToJS
    Nov 23 '18 at 2:28














0












0








0








I made a mini system to upload photos as profile and cover, but when I put the two includes 1 if it works and the other does not work when putting the other include. If anyone knows help me please



the 2 are from the same base but different tables, what I want is to connect the 2 tables so that they work without any error



I am new at this






====table 1==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_banner` ";
$ res = mysqli_query ($ cn, $ sql);
?>

====table 2==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_profile` ";
$ res = mysqli_query ($ cn, $ sql);
?>












share|improve this question














I made a mini system to upload photos as profile and cover, but when I put the two includes 1 if it works and the other does not work when putting the other include. If anyone knows help me please



the 2 are from the same base but different tables, what I want is to connect the 2 tables so that they work without any error



I am new at this






====table 1==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_banner` ";
$ res = mysqli_query ($ cn, $ sql);
?>

====table 2==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_profile` ";
$ res = mysqli_query ($ cn, $ sql);
?>








====table 1==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_banner` ";
$ res = mysqli_query ($ cn, $ sql);
?>

====table 2==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_profile` ";
$ res = mysqli_query ($ cn, $ sql);
?>





====table 1==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_banner` ";
$ res = mysqli_query ($ cn, $ sql);
?>

====table 2==

include ("conexion.php");
$ sql = "SELECT * FROM` daniel_profile` ";
$ res = mysqli_query ($ cn, $ sql);
?>






javascript php html mysql mysqli






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 1:47









danielmezadanielmeza

11




11













  • Why are you using include() to the same file twice? Also don't use the same variable names for your database query $sql = > $res you are over writing them. Use different ones and see if you get data from both tables.

    – NewToJS
    Nov 23 '18 at 1:50








  • 1





    You can do all of this in SQL (and should - it is made for this stuff!). Once you have that, then come use the SQL statement in PHP code. You want to read up on relations between tables, primary keys, foreign keys, sub-selects, and joins.

    – ivanivan
    Nov 23 '18 at 1:57











  • @ivanivan What do you mean "You can do all of this in SQL" The Op is using php to make a SQL Database connection and query.... What does this have to do with primary keys? The OP wants to create a database connection (which is done) but then execute a query to get all data from two tables.... The problem is using duplicate variable names which is causing a over write of the first one or so I believe.... If I am wrong please explain as this will be helpful to me too, thank you.

    – NewToJS
    Nov 23 '18 at 2:03













  • @NewToJS if there is a relationship between the data then you can select table1.column, table2.column where table1.othercol=table2.othercol. Or you can use joins. Or you can subselect. SQL is incredibly powerful, and if you are wanting to "connect two tables together" and there is any kind of relationship to the data they contain then do it in SQL. Without seeing the OPs actual database structure and a sample of desired output (or use), I can't give him a good SQL statement. Now if the data is totally unrelated, then yes, the solution of using 2 different vars for results is the thing.

    – ivanivan
    Nov 23 '18 at 2:17








  • 1





    @ivanivan I understand what you mean and completely agree. Without knowing the structure of the tables and if a relation of the two exist it is hard to offer a solution. I wasn't clear on your suggestion based on the first comment but with more detail I understand where you are going with your suggestion. I think we need more information before being able to offer anything more than the suggestions given so far.

    – NewToJS
    Nov 23 '18 at 2:28



















  • Why are you using include() to the same file twice? Also don't use the same variable names for your database query $sql = > $res you are over writing them. Use different ones and see if you get data from both tables.

    – NewToJS
    Nov 23 '18 at 1:50








  • 1





    You can do all of this in SQL (and should - it is made for this stuff!). Once you have that, then come use the SQL statement in PHP code. You want to read up on relations between tables, primary keys, foreign keys, sub-selects, and joins.

    – ivanivan
    Nov 23 '18 at 1:57











  • @ivanivan What do you mean "You can do all of this in SQL" The Op is using php to make a SQL Database connection and query.... What does this have to do with primary keys? The OP wants to create a database connection (which is done) but then execute a query to get all data from two tables.... The problem is using duplicate variable names which is causing a over write of the first one or so I believe.... If I am wrong please explain as this will be helpful to me too, thank you.

    – NewToJS
    Nov 23 '18 at 2:03













  • @NewToJS if there is a relationship between the data then you can select table1.column, table2.column where table1.othercol=table2.othercol. Or you can use joins. Or you can subselect. SQL is incredibly powerful, and if you are wanting to "connect two tables together" and there is any kind of relationship to the data they contain then do it in SQL. Without seeing the OPs actual database structure and a sample of desired output (or use), I can't give him a good SQL statement. Now if the data is totally unrelated, then yes, the solution of using 2 different vars for results is the thing.

    – ivanivan
    Nov 23 '18 at 2:17








  • 1





    @ivanivan I understand what you mean and completely agree. Without knowing the structure of the tables and if a relation of the two exist it is hard to offer a solution. I wasn't clear on your suggestion based on the first comment but with more detail I understand where you are going with your suggestion. I think we need more information before being able to offer anything more than the suggestions given so far.

    – NewToJS
    Nov 23 '18 at 2:28

















Why are you using include() to the same file twice? Also don't use the same variable names for your database query $sql = > $res you are over writing them. Use different ones and see if you get data from both tables.

– NewToJS
Nov 23 '18 at 1:50







Why are you using include() to the same file twice? Also don't use the same variable names for your database query $sql = > $res you are over writing them. Use different ones and see if you get data from both tables.

– NewToJS
Nov 23 '18 at 1:50






1




1





You can do all of this in SQL (and should - it is made for this stuff!). Once you have that, then come use the SQL statement in PHP code. You want to read up on relations between tables, primary keys, foreign keys, sub-selects, and joins.

– ivanivan
Nov 23 '18 at 1:57





You can do all of this in SQL (and should - it is made for this stuff!). Once you have that, then come use the SQL statement in PHP code. You want to read up on relations between tables, primary keys, foreign keys, sub-selects, and joins.

– ivanivan
Nov 23 '18 at 1:57













@ivanivan What do you mean "You can do all of this in SQL" The Op is using php to make a SQL Database connection and query.... What does this have to do with primary keys? The OP wants to create a database connection (which is done) but then execute a query to get all data from two tables.... The problem is using duplicate variable names which is causing a over write of the first one or so I believe.... If I am wrong please explain as this will be helpful to me too, thank you.

– NewToJS
Nov 23 '18 at 2:03







@ivanivan What do you mean "You can do all of this in SQL" The Op is using php to make a SQL Database connection and query.... What does this have to do with primary keys? The OP wants to create a database connection (which is done) but then execute a query to get all data from two tables.... The problem is using duplicate variable names which is causing a over write of the first one or so I believe.... If I am wrong please explain as this will be helpful to me too, thank you.

– NewToJS
Nov 23 '18 at 2:03















@NewToJS if there is a relationship between the data then you can select table1.column, table2.column where table1.othercol=table2.othercol. Or you can use joins. Or you can subselect. SQL is incredibly powerful, and if you are wanting to "connect two tables together" and there is any kind of relationship to the data they contain then do it in SQL. Without seeing the OPs actual database structure and a sample of desired output (or use), I can't give him a good SQL statement. Now if the data is totally unrelated, then yes, the solution of using 2 different vars for results is the thing.

– ivanivan
Nov 23 '18 at 2:17







@NewToJS if there is a relationship between the data then you can select table1.column, table2.column where table1.othercol=table2.othercol. Or you can use joins. Or you can subselect. SQL is incredibly powerful, and if you are wanting to "connect two tables together" and there is any kind of relationship to the data they contain then do it in SQL. Without seeing the OPs actual database structure and a sample of desired output (or use), I can't give him a good SQL statement. Now if the data is totally unrelated, then yes, the solution of using 2 different vars for results is the thing.

– ivanivan
Nov 23 '18 at 2:17






1




1





@ivanivan I understand what you mean and completely agree. Without knowing the structure of the tables and if a relation of the two exist it is hard to offer a solution. I wasn't clear on your suggestion based on the first comment but with more detail I understand where you are going with your suggestion. I think we need more information before being able to offer anything more than the suggestions given so far.

– NewToJS
Nov 23 '18 at 2:28





@ivanivan I understand what you mean and completely agree. Without knowing the structure of the tables and if a relation of the two exist it is hard to offer a solution. I wasn't clear on your suggestion based on the first comment but with more detail I understand where you are going with your suggestion. I think we need more information before being able to offer anything more than the suggestions given so far.

– NewToJS
Nov 23 '18 at 2:28












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439766%2fhow-to-connect-2-tables-from-the-same-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439766%2fhow-to-connect-2-tables-from-the-same-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?