Help - Search - Members - Calendar
Full Version: Quick PHP Question
Invision Power Services > Community Forums > Community Web Design and Coding
LoR*Evanescence
I have a quick question about php, hopefully some one can answer me=)

I only know basic php, such as include and requre commands that I use on my site.

What I'm trying to do is include a diffrent file if a diffrent link was clicked to enter the page.


They page I'm making is a lyrics page, The main lyrics page has the song names, then I want the links to pop up a window which displays the lyrics in a fancy graphics layout. I'm trying to make this work so I only need one php page file to call in all the diffrent lyrics depending on what link was pressed.

If some one could give me a couple pointers on how to do this I would really appreciate it.

thanks.
Chad
What you want is to express a variable within the link.

Done like so:

QUOTE


The variable name is "var."
The setting to that variable is 2.

What you would do then is:

CODE
if ($_GET['var']=='2')
{
print "Display some stuff";
}
elseif ($_GET['var']=='1')
{
print "Display and alternate";
}
else
{
print "This is default if the criteria above is not met.";
}


You want to be sure to make sure that info from URLs is save...

Chad
LoR*Evanescence
QUOTE(Chad @ Mar 9 2005, 06:17 PM)
What you want is to express a variable within the link.

Done like so:
The variable name is "var."
The setting to that variable is 2.

What you would do then is:

CODE
if ($_GET['var']=='2')
{
print "Display some stuff";
}
elseif ($_GET['var']=='1')
{
print "Display and alternate";
}
else
{
print "This is default if the criteria above is not met.";
}


You want to be sure to make sure that info from URLs is save...

Chad
*



Thanks, I'll give it a try=)
Chad
No problem.
There is little explanation there as to how to do it with precise detail.

But if errors or questions arise.

There is always somebody here willing to help. original.gif

Chad
LoR*Evanescence
QUOTE(Chad @ Mar 9 2005, 06:22 PM)
No problem.
There is little explanation there as to how to do it with precise detail.

But if errors or questions arise.

There is always somebody here willing to help. original.gif

Chad
*




Here is an error I'm getting.

"Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in seeingred.php on line 86"

here is the line of code. Any idea why its saying this?


print "<span class="songname">Don't Leave Me Alone</span>";
wbear
It "sees" the second quote mark, and thinks it's done. Use a single quote arround the full string:
print '<span class="songname">Don't Leave Me Alone</span>';
Chad
The quoting in PHP can be confusing. But simple nonetheless.

When creating a string of text. Surround it in Double quotes. Any quote used inside the Double quotes should be single quotes. Unless you undoubtly need to use Double Quotes, escape it with \.

This tells PHP that the Double quote is to be Printed and not parsed.

Chad
LoR*Evanescence
OK, I figured it out and got it working


www.lettysunderground.com/lyrics.php

Just click on any song name for Seeing Red or Fifteen Will Get You Twenty. I still need to do Goes on a Fieldtrip some time, ran out of time tonight.


Thanks everyone original.gif
Chad
Congrats.

This way may not be the most efficient way, but works, nonetheless.

As you learn more PHP coding and techniques, more efficient ways will become more apparent.

My assignment to you is to research a more efficient way of do this exact same thing.
If you need help on finding where to develop a more efficient way, I am glad to help.

I am letting you research this so it can have time to be locked into memory.

I am deep in belief that if you research this on your own. You are more than likely to remember the techniques.

This is how I learned PHP, and I know more about it than everything I have ever learned in school.

Chad
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.