...

View Full Version : Displaying multiple pages on one page



Deacon Frost
03-13-2008, 06:30 AM
Ok, so here's what I want to do:

I have a page where you click to browse several database entries. This page is called "Portfolios.php".

Whenever you click one of the entries, it takes you to a page that shows all of their information, portfolio, etc.

What I want it to do, is when you click an entry on portfolios.php, it does a query string where it takes you to, for instance, portfolios.php?id=1. The layout of portfolios.php?id=1 is DIFFERENT than portfolios.php... but it should ALL be stored in 1 .php file.

I can do this to a different page, however, I don't know how to do it on the same page.

Could I use a simple if statement to echo an entire page of html? But that would be very difficult to collaborate.

I was thinking of using a different page, but doing this would be much more efficient for working it.


And another thought I had was includes.
if{$url == "portfolios.php") { include(portfolios1.php); }
else { include(portfolios2.php); }

then just have forms in each included file...


would that work right?

or is there a better way of going about this?

p4plus2
03-13-2008, 06:47 AM
Try something like this:
it can be used for styles (as shown) or to change the page.


<?php
$id = $_GET['id'];
if($id == ''){
//code or include goes here
}
elseif($id == 1){
// code or include goes here
}
//repeat for all styles/pages.
?>


Let me know if this helped yah :)

Deacon Frost
03-13-2008, 07:15 AM
Yeah, I see that being the best method. So, if I edit it to be like...


<?php
$id = $_GET['id'];

if(!$id){
// page with forms to select id goes here
}
else
{
// include link that has the selected entry setup here
}
//repeat for all styles/pages.
?>



Can a form send data to the page it's on as well as display data?


Update:

Well, I've tried some things, and I keep getting a parse error. I know the problem is with my above code, cause I have nothing sending the ID to the page to determine if there is an id or not.


I'm gonna try to find a url function, so if the url !="profiles.php?id=" then it will show one page, but if it is, it'll show the other..

I dunno how it's gonna work tho.

It works fine going to the page when the page is all laid out, but when I put variables on the page, it all messes up.


Further Edit (read if you think you can help):

Here's all the pages in order:

(This one is the main page. Portfolios.php. It should show portfolios1.php (an include) by default.)


<?php include("/home/deacon/public_html/critical/includes/header.php"); ?>

<body>

<div class="left">

<ul>
<li><a href="index.php">Home</a></li>
<li class="active"><a href="portfolio.php">Portfolio</a></li>
<li><a href="services.php">Services</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>

</div>

<div class="right">


<div class="content">
<?php
$id = $_GET['id'];

if(!isset($id)){
include("/home/deacon/public_html/portfolios1.php");
}
else
{
include("/home/deacon/public_html/portfolios2.php");
}
//repeat for all styles/pages.
?>

<? include("/home/deacon/public_html/critical/includes/footer.php"); ?>


(This is portfolios1.php. It is what should be automatically displayed on portfolios.php)


<?php
include("/home/deacon/public_html/critical/includes/profilesconn.php");
$sql = "SELECT ID,Name,Rank FROM profile ORDER BY ID LIMIT 30";
$result = mysql_query( $sql ) or die('The error was: ' . mysql_error() . '<br>The query was: ' . $sql);
$num = mysql_num_rows($result);
if($num > 0)
{
while($row = mysql_fetch_assoc($result))
{
$id = $row['ID'];
$name = $row['Name'];
$rank = $row['Rank'];
?>

<center>
<table width="75&#37;">
<tr>
<td>
<h1>ID</h1>
<td>
<h1>Name</h1>
<td>
<h1>Rank</h1>
<tr>
<td>
<a href="http://www.chrysys.net/portfolios.php?id=<?php echo $id ?>"><?php echo $id ?></a>
<td>
<a href="http://www.chrysys.net/portfolios.php?id=<?php echo $id ?>"><?php echo $name ?></a>
<td>
<?php echo $rank ?>
</td>
</tr>
</table>
<?php
}
}
?>
</center>


(and this is portfolios2.php (another include). When the user goes to portfolios.php they should see the above, UNLESS they have clicked an id number, then they should see the below.)


<?php
include("/home/deacon/public_html/critical/includes/profilesconn.php");

$id = $_GET['id'];

$sql = "SELECT ID,Name,Rank,1,2,3,4,5,About,Interests,Services,Portfolio FROM profile WHERE ID=' $id '";
$result = mysql_query( $sql ) or die('The error was: ' . mysql_error() . '<br />The query was: ' . $sql);
$num = mysql_num_rows($result);
if($num > 0);
{
while($row = mysql_fetch_assoc($result));
{
$id = $row['ID'];
$name = $row['Name'];
$rank = $row['Rank'];
$_1 = $row['1'];
$_2 = $row['2'];
$_3 = $row['3'];
$_4 = $row['4'];
$_5 = $row['5'];
$about = $row['About'];
$interests = $row['Interests'];
$services = $row['Services'];
$portfolio = $row['Portfolio'];

?>




<table width="75%">
<tr>
<td>
<a href="http://www.chrysys.net"><img src="/critical/images/me.jpg" alt="Find All of Deacon's Work" width="150" height="200" align="left" /></a>
<h1><? echo $name; ?></h1>
<h2><? echo $rank; ?></h2>
<hr>
<center><h2>Best Top 5</h2>
<ol>
<li><span><? echo $_1; ?></span></li>
<li><span><? echo $_2; ?></span></li>
<li><span><? echo $_3; ?></span></li>
<li><span><? echo $_4; ?></span></li>
<li><span><? echo $_5; ?></span></li>
</ol>
</center>
</td>
</tr>
</table>

<table width="75%">
<tr>
<td align>
<h2>About Me</h2>
<?php echo $about; ?>
</td>
</tr>
</table>

<br /><br />

<table width="75%">
<tr>
<td>
<h2>My Interests</h2>
<?php echo $interests; ?>
</td>
</tr>
</table>


<br /><br />

<table width="75%">
<tr>
<td>
<h2>My Services</h2>
<?php echo $services; ?>
</td>
</tr>
</table>


<br /><br />

<table width="75%">
<tr>
<td>
<h2>My Portfolio</h2>
<?php echo $portfolio; ?>
</td>
</tr>
</table>



This is the error I get:



Parse error: syntax error, unexpected $end in /home/deacon/public_html/portfolios2.php on line 93


That would be the very end of portfolios2.php:



</table>



Hope someone understands :P.



Even FURTHER edit:

Well, I did some looking, and I guess I left some things open.

So I fixed it :P. It was in the portfolios2, cuz i had copied some of my previously used code without deleting or closing properly.

However, now I face a new error.


I got it to take me to the page, yet it does not retrieve data sent from the portfolios1 page. I can't figure out why it won't $_GET the $id from that page... so I dunno.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum