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.
php mysql sql webpage
add a comment |
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.
php mysql sql webpage
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
add a comment |
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.
php mysql sql webpage
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
php mysql sql webpage
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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