Jump to content

Links pull info from separate php file to main table


Dhaling2011

Recommended Posts

Hi.. been a while since I have touched php and need some help. What I am trying to do is have my links pull text from separate php files, and load them into main table. Here is my old php code..used to work..

I had my index.php with my website template on it. In the table I want my info to appear i put this code.

 

<?php /* START MAIN AREA HERE */

if($news) include("news.php");

elseif($bio) include("bio.php");

elseif($draw) include("draw.php");

elseif($pic) include("pic.php");

else include("news.php");

/* END HERE */?>

 

My link looks like this.

 

<A HREF="?news=x"

ONMOUSEOVER="changeImages('home', 'images/home-over.gif'); return true;"

ONMOUSEOUT="changeImages('home', 'images/home.gif'); return true;">

<IMG NAME="home" SRC="images/home.gif" WIDTH=69 HEIGHT=31 BORDER=0 ALT=""></A>

 

Any help much appreciated!

 

Link to comment
Share on other sites

Here's a very simple example.

 

<?php
if(!isset($_GET['link'])){
$link = "home";
}

echo "<a href='?link=home'>Home</a> <a href='?link=news'>News</a> <a href='?link=bio'>Bio</a> <a href='?link=pic'>Pic</a> <a href='?link=draw'>Draw</a><p>";

if ($link == "news"){
include('news.php');
} elseif ($link == "bio"){
include('bio.php');
} elseif ($link == "pic"){
include('pic.php');
} elseif ($link == "draw"){
include('draw.php');
} else {
include('home.php');
}
?>

 

Here's a demo of it.

http://get.blogdns.com/navigation/

Link to comment
Share on other sites

Hmm Put code in.. but it is not changing between the pages?

 

My links are in its own table.. looking like this..

 

 

<a href='?link=main'>Home</a>

<a href='?link=history'>History</a>

<a href='?link=bio'>Bio</a>

 

 

And where I want my info to appear in another table.. it looks like this..

 

<?php

if(!isset($_GET['link'])){

$link = "main";

}

if ($link == "history"){

include('history.php');

} elseif ($link == "bio"){

include('bio.php');

} else {

include('main.php');

}

?>

 

 

My main info page is apprearing just fine. But will not pull up any other links..always appears as main.php?

Link to comment
Share on other sites

I suggest using AJAX.  I use it on my own site, to perform the same function. Here is some of the code:

 

index page head

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/linkget.js"></script>
</head>

 

the first script is a global script, much like prototype.js.  The second is where you manage your links:

$(document).ready(function(){
// load about page when the page loads
$("#response").load("about.php");
// load another page
$("#another").click(function(){
 	$("#response").load("another.php");
});
// load another page
$("#another1").click(function(){
 	$("#response").load("another1.php");
});
});

Where $(#another).click(function(){

$"#response").load("another.php");

id tag of the link, id tag of where you want it to go (this MUST stay as #response, as it's defined in the outside javascript), and page

 

And on the page, call to the links as so:

<a href="#" class="nav" id="about">About</a>
<a href="#" class="nav" id="another">Another</a>
<a href="#" class="nav" id="another1">Another1</a>

<div id="#response">&nbsp</div>

 

This is what you should be doing instead of trying to fuss with includes.

 

Link to comment
Share on other sites

;) Thank you! It works! Just what I needed. Something simple. How compatible is Ajax with browsers?

 

You're welcome.

 

AJAX is really just a bunch of javascript with a few exceptional calls.  It's pretty much supported by every browser, unless you're using IE 3 or something.  You can read up more on it and it's calls on just about as many places as you'll find PHP tuts.

Link to comment
Share on other sites

This is what you should be doing instead of trying to fuss with includes.

 

I respectfully disagree. Clients can alter they're javascript settings all the way to blocking them completely and then where are you?

 

IMO js/jquery/ajax should only be used for 2 reasons:

    1. to create a smoother user experience or cool functionality, but must have a way to gracefully degrade

    2. when there's no other way

 

The includes example QuickOldCar provided worked for me, so it must be an issue with the code

 

AJAX is really just a bunch of javascript with a few exceptional calls.  It's pretty much supported by every browser, unless you're using IE 3 or something.  You can read up more on it and it's calls on just about as many places as you'll find PHP tuts.

 

This is true, but see above

 

These are just my opinions and intended to give the OP something to think about

Link to comment
Share on other sites

 

I respectfully disagree. Clients can alter they're javascript settings all the way to blocking them completely and then where are you?

 

IMO js/jquery/ajax should only be used for 2 reasons:

    1. to create a smoother user experience or cool functionality, but must have a way to gracefully degrade

    2. when there's no other way

 

I agree with your disagreement.  However, most every client manages a whitelist of sorts to which permits then to modify their config allowing certain sites permission to use scripts.  As the developer, we need to maintain a fail-safe for the small percentage of those who have it blocked completely or do not yet trust your site enough to allow scripts to run.  Those are the command decisions that must be made, and using the if/else include script listed above is a decent fallback, furthermore, so is naming static pages completely. 

 

However, clients have come to expect a bit of flair when visiting a site, and do attribute site quality with how long they'll stay and browse, or even if they will purchase from you.  That being said, you can't even order pizza online without having SOME scripting functionality.  :P

Link to comment
Share on other sites

I agree with your disagreement.  However, most every client manages a whitelist of sorts to which permits then to modify their config allowing certain sites permission to use scripts.  As the developer, we need to maintain a fail-safe for the small percentage of those who have it blocked completely or do not yet trust your site enough to allow scripts to run.  Those are the command decisions that must be made, and using the if/else include script listed above is a decent fallback, furthermore, so is naming static pages completely. 

 

However, clients have come to expect a bit of flair when visiting a site, and do attribute site quality with how long they'll stay and browse, or even if they will purchase from you.  That being said, you can't even order pizza online without having SOME scripting functionality.  :P

 

I do know what you mean. It's just something I thought he should consider and is just my opinion  :D

Link to comment
Share on other sites

makes alot of sense. both ways. the site is very small..so not to worried about lot of includes.

 

I think where I am going wrong on the php code I was given is I am trying to separate the links to one table and the main text to another? so I tried to cut it up..which made it not work.

Not sure how to go about that?

Link to comment
Share on other sites

I do not understand your dilemna, Dhaling.  If you are using the if/else method as stated above, your links can be anywhere on the page, so long as your include() is where you want it to belong.  It'll just load the page where you have the include array.

 

If you're working off the AJAX script i gave you, the links can as well be anywhere you wish.  The page that comes in, is loaded between <div id="response> and </div>.

Link to comment
Share on other sites

Well.. this is what I have so far.. and what I need help on ..I think it is the (include function). When you first go to the page, I am getting an error in the main, because it doesn't know what to pull up. But the links are working perfectly. Not sure how to include? here is the link..

 

http://www.jansplayworks.com/adventure/

 

I have this code in my header.

 

<?php

$incMiddle = "$_GET[midPage]" . ".php";

?>

 

This is in my main..

 

<?php

include ("http://www.jansplayworks.com/adventure/$incMiddle");

 ?>

 

 

 

This is my menu..

 

<a href="index.php?midPage=history">Test</a>

<a href="index.php?midPage=main">Test</a>

 

 

Link to comment
Share on other sites

I see several issues regarding the code.  The default page isn't being loaded, because what you're telling it to load is only ".php" because of how you defined your variable $incMiddle makes it null.  If you take a look at QuickOldCar's reply to you, you see he has pre-defined the page to be loaded when index.php is initially ran.

<?php
if(!isset($_GET['link'])){
$link = "home";
}

 

!isset is telling the script that if no page has been queried yet by the client user, the default included php file should be "home".  From looking at you're site, I'm inferring that you want the Home link to be the default.  It's page name is main.php.  So swap that part out, and it should work just fine.

 

If I may offer some criticism however, there are many design flaws that make your site hard to read through, and quite honestly, unprofessional.  These days, websites are an assumed reflection of the service you would receive, and a poorly crafted site can leave a bad impression.

 

The navigation links on the left actually fall to the bottom of the table cell when the links are clicked and a large page is loaded.  Looking at the source code, you only have a single table, and this is causing you a heap of problems.  Also, the way you have the logo sliced is uneven and is causing you to write some table funny code to get it to match up correctly.  The third major issue I have with your site layout is the use of graphics for borders, and even the footer of the page is a graphic.

 

If I may be so bold as to offer as how I would approach the design, I would do the following:

*Slice the logo image vertically. This would load uniformly, and clean up your code.

*Ditch the border and footer images.  These can be coded with simple CSS.  It also requires the client to load less data from your server.  If you chose to use an image as a border, and the image doesn't fluctuate, make it a single pixel wide or long, and use CSS to repeat it.

*Place the very few amount of links you have (7) in a vertical arrangement under the header.  The links will be better presented for the client user to use.

*Use some CSS.  All of your styling can be done in a single file where you can manage the look and feel of all presented media.  Having all of your text bolded and your links the default blue & purple is awful to look at.

 

These are solely my suggestions, and you are free to disregard them as you wish.  Hopefully my initial response will achieve your goal, and you can have your site running as intended.  Best of Luck!

Link to comment
Share on other sites

Thanks for the critiques..but the site is close to be done.. i just wanted to make sure I could get the php to work..before attempting to actually fix the table ect. It is just a rough draft. but I will definatley make the footer just text.. as well as reslicing the header.  the links are going to be images in the end. with mouseovers. But yeah. I really have not  spent any  time on the design aspect yet :D 

Link to comment
Share on other sites

Ahh this is frustrating. I dont understand why this isnt working. I must be missing something. Now I am getting this error..

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home4/jansplay/public_html/adventure/index.php on line 6

 

It is in this some where..

 

<?php

if(!isset($_GET['link'])){

$link = "main";

}

?>

 

It is not liking      $link - "main";

Link to comment
Share on other sites

I had a few tips that your site was a draft - your original post mentioned an image, and your title was "tester".  But, I couldn't help myself when I seen the page  :P

 

As far as this error you're getting, esure you're not using the dash. It looks like it was pasted in, so double check that first.

$link - "main";

 

And try to surround your code/php blocks with the little symbols below the font selection drop down.

Link to comment
Share on other sites

Sorry. I have that in the header of the index.php. Here is my whole code.

<html>
<head>
<?php
if(!isset($_GET['link'])){
$link = "main";
}
?>

<title>tester3</title>

</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (tester3.psd) -->
<table id="Table_01" width="813" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td colspan="3">
		<img src="images/index_01.gif" width="733" height="1" alt=""></td>
	<td colspan="2" rowspan="4">
		<img src="images/top3.gif" width="80" height="229" alt=""></td>
</tr>
<tr>
	<td rowspan="2">
		<img src="images/top1.gif" width="125" height="227" alt=""></td>
	<td colspan="2">
		<img src="images/top2.gif" width="608" height="89" alt=""></td>
</tr>
<tr>
	<td colspan="2">
		<img src="images/title.gif" width="608" height="138" alt=""></td>
</tr>
<tr>
	<td colspan="3">
		<img src="images/index_06.gif" width="733" height="1" alt=""></td>
</tr>
<tr>
	<td colspan="5">
		<img src="images/profit.gif" width="813" height="39" alt=""></td>
</tr>
<tr>
	<td colspan="2">
		<img src="images/index_08.gif" width="202" height="1" alt=""></td>
	<td colspan="2" rowspan="2" background='images/main.gif' WIDTH=590 height='100%' align='center' valign='top'><b>


<?php
 ($link == "hours"){
include('hours.php');
} elseif ($link == "location"){
include('location.php');
} elseif ($link == "about"){
include('about.php');
} elseif ($link == "members"){
include('members.php');} 

} elseif ($link == "staff"){
include('staff.php');
} elseif ($link == "members"){
include('members.php');
elseif ($link == "faq"){
include('faq.php');
elseif ($link == "contact"){
include('contact.php');
} else {
include('main.php');
}
?>




	</td>
	<td rowspan="2" background='images/right.gif' WIDTH=21 height='100%' align='center' valign='top'></td>
</tr>
<tr>
	<td colspan="2" background='images/menu.gif' WIDTH=202 height='100%' align='center' valign='top'><b>


<a href='?link=main'>Home</a>
<br>
<a href='?link=hours'>Hours</a>
<br><a href='?link=location'>Location</a>
<br><a href='?link=about'>About</a><br>
<a href='?link=members'>Members</a><br>
<a href='?link=staff'>Staff</a><br>
<a href='?link=Contact Us'>Contact Us</a><br>
<a href='?link=faq'>FAQ</a><br>




	</td>
</tr>
<tr>
	<td colspan="5">
		<img src="images/index_12.gif" width="813" height="50" alt=""></td>
</tr>
<tr>
	<td>
		<img src="images/spacer.gif" width="125" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="77" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="531" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="59" height="1" alt=""></td>
	<td>
		<img src="images/spacer.gif" width="21" height="1" alt=""></td>
</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>

 

The place with problem

  
<html>
<head>
<?php
if(!isset($_GET['link'])){
$link = "main";
}
?>

 

 

Link to comment
Share on other sites

I dost believe your problem is using the 'if' statement without 'else'.  The condition has a statement, but doesn't have any fallback.  You could use while statement instead.

 

while (!isset($_GET['link'])){
$link="main";
}

 

Basically just tells the server "while the link isn't set, use main"

Link to comment
Share on other sites

Well at least the error changed! lol Put this

<?php
while (!isset($_GET['link'])){
$link="main";
}
?>

 

Got this as an error. it is not happy with my brackets?

Parse error: syntax error, unexpected '{' in /home4/jansplay/public_html/adventure/index.php on line 4

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.