Php - Display page content from multiple tables?











up vote
0
down vote

favorite












My contents of website are display from a table (ex. ContentTable) with pure Ajax. There are 5 pages.
My problem is that, I would like to use another table, but ONLY on page 3.
For example:



ContentTable:



pageid | header       | content       |...
1 | "Welcome" | "Main Page" |...
3 | AnotherTable(fruits) |...


Table2



id | type      | description
1 | fruit | "In botany, a fruit is the...."
2 | vegetable | "Vegetables are parts of...."


Table3



id | type | name | description
1 | fruit| apple| "An apple is a sweet...."
...


In this case I would like to display apple on page 3.



Example for the SQL:



I get the current page like:
$GetPageID = isset($_GET['pg']);



The basic sql is like:
SELECT header, content FROM content WHERE pageid=$GetPageID



/* run extra SQL query */
if ($GetPageID == 3){
$SQL = "SELECT type, description From Table2;"
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo 'Type: '.$row["type"].'<br>Description: '.$row["description"].'<br><a href="...">Show more about'.$row["type"].'</a>';
}
} else {
echo "the table is empty";
}
}


But I would like to use just a single query.










share|improve this question




















  • 3




    We can't see your coding attempt. Your question is currently Too Broad.
    – mickmackusa
    Nov 10 at 13:25












  • You must provide an example that can be used to reproduce your error. Please update your question accordingly.
    – Adam Chubbuck
    Nov 10 at 13:54










  • @Adam Chubbuck Hey! I have no error. I haven’t any idea, how to make it work.
    – Adam
    Nov 10 at 14:03

















up vote
0
down vote

favorite












My contents of website are display from a table (ex. ContentTable) with pure Ajax. There are 5 pages.
My problem is that, I would like to use another table, but ONLY on page 3.
For example:



ContentTable:



pageid | header       | content       |...
1 | "Welcome" | "Main Page" |...
3 | AnotherTable(fruits) |...


Table2



id | type      | description
1 | fruit | "In botany, a fruit is the...."
2 | vegetable | "Vegetables are parts of...."


Table3



id | type | name | description
1 | fruit| apple| "An apple is a sweet...."
...


In this case I would like to display apple on page 3.



Example for the SQL:



I get the current page like:
$GetPageID = isset($_GET['pg']);



The basic sql is like:
SELECT header, content FROM content WHERE pageid=$GetPageID



/* run extra SQL query */
if ($GetPageID == 3){
$SQL = "SELECT type, description From Table2;"
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo 'Type: '.$row["type"].'<br>Description: '.$row["description"].'<br><a href="...">Show more about'.$row["type"].'</a>';
}
} else {
echo "the table is empty";
}
}


But I would like to use just a single query.










share|improve this question




















  • 3




    We can't see your coding attempt. Your question is currently Too Broad.
    – mickmackusa
    Nov 10 at 13:25












  • You must provide an example that can be used to reproduce your error. Please update your question accordingly.
    – Adam Chubbuck
    Nov 10 at 13:54










  • @Adam Chubbuck Hey! I have no error. I haven’t any idea, how to make it work.
    – Adam
    Nov 10 at 14:03















up vote
0
down vote

favorite









up vote
0
down vote

favorite











My contents of website are display from a table (ex. ContentTable) with pure Ajax. There are 5 pages.
My problem is that, I would like to use another table, but ONLY on page 3.
For example:



ContentTable:



pageid | header       | content       |...
1 | "Welcome" | "Main Page" |...
3 | AnotherTable(fruits) |...


Table2



id | type      | description
1 | fruit | "In botany, a fruit is the...."
2 | vegetable | "Vegetables are parts of...."


Table3



id | type | name | description
1 | fruit| apple| "An apple is a sweet...."
...


In this case I would like to display apple on page 3.



Example for the SQL:



I get the current page like:
$GetPageID = isset($_GET['pg']);



The basic sql is like:
SELECT header, content FROM content WHERE pageid=$GetPageID



/* run extra SQL query */
if ($GetPageID == 3){
$SQL = "SELECT type, description From Table2;"
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo 'Type: '.$row["type"].'<br>Description: '.$row["description"].'<br><a href="...">Show more about'.$row["type"].'</a>';
}
} else {
echo "the table is empty";
}
}


But I would like to use just a single query.










share|improve this question















My contents of website are display from a table (ex. ContentTable) with pure Ajax. There are 5 pages.
My problem is that, I would like to use another table, but ONLY on page 3.
For example:



ContentTable:



pageid | header       | content       |...
1 | "Welcome" | "Main Page" |...
3 | AnotherTable(fruits) |...


Table2



id | type      | description
1 | fruit | "In botany, a fruit is the...."
2 | vegetable | "Vegetables are parts of...."


Table3



id | type | name | description
1 | fruit| apple| "An apple is a sweet...."
...


In this case I would like to display apple on page 3.



Example for the SQL:



I get the current page like:
$GetPageID = isset($_GET['pg']);



The basic sql is like:
SELECT header, content FROM content WHERE pageid=$GetPageID



/* run extra SQL query */
if ($GetPageID == 3){
$SQL = "SELECT type, description From Table2;"
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo 'Type: '.$row["type"].'<br>Description: '.$row["description"].'<br><a href="...">Show more about'.$row["type"].'</a>';
}
} else {
echo "the table is empty";
}
}


But I would like to use just a single query.







php mysql sql webpage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 11:45

























asked Nov 10 at 13:23









Adam

156




156








  • 3




    We can't see your coding attempt. Your question is currently Too Broad.
    – mickmackusa
    Nov 10 at 13:25












  • You must provide an example that can be used to reproduce your error. Please update your question accordingly.
    – Adam Chubbuck
    Nov 10 at 13:54










  • @Adam Chubbuck Hey! I have no error. I haven’t any idea, how to make it work.
    – Adam
    Nov 10 at 14:03
















  • 3




    We can't see your coding attempt. Your question is currently Too Broad.
    – mickmackusa
    Nov 10 at 13:25












  • You must provide an example that can be used to reproduce your error. Please update your question accordingly.
    – Adam Chubbuck
    Nov 10 at 13:54










  • @Adam Chubbuck Hey! I have no error. I haven’t any idea, how to make it work.
    – Adam
    Nov 10 at 14:03










3




3




We can't see your coding attempt. Your question is currently Too Broad.
– mickmackusa
Nov 10 at 13:25






We can't see your coding attempt. Your question is currently Too Broad.
– mickmackusa
Nov 10 at 13:25














You must provide an example that can be used to reproduce your error. Please update your question accordingly.
– Adam Chubbuck
Nov 10 at 13:54




You must provide an example that can be used to reproduce your error. Please update your question accordingly.
– Adam Chubbuck
Nov 10 at 13:54












@Adam Chubbuck Hey! I have no error. I haven’t any idea, how to make it work.
– Adam
Nov 10 at 14:03






@Adam Chubbuck Hey! I have no error. I haven’t any idea, how to make it work.
– Adam
Nov 10 at 14:03



















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',
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%2f53239380%2fphp-display-page-content-from-multiple-tables%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239380%2fphp-display-page-content-from-multiple-tables%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."