PDA

View Full Version : PHP Code not working just right...


xero-infinity
4-15-02, 08:56 PM
I don't believe this is coded right or something. Help needed... Take a look at the page and then I have the code below...
http://xero-infinity.com/php/test.php

#!/usr/local/bin/php
<html><head><title>PHP Test</title></head>
<body>
<?php
if ($sect) {
include("$sect.txt");
}
else {
include("home.txt");
}
?><br>
<?php
if ($sect) {
include("$sect.txt");
}
else {
include("test.txt");
}
?><br>
<?php
if ($sect) {
include("$sect.txt");
}
else {
include("test2.txt");
}
?><br>
<?php
if ($sect) {
include("$sect.txt");
}
else {
include("test3.txt");
}
?><br>
<?php
if ($sect) {
include("$sect.txt");
}
else {
include("test4.txt");
}
?><p>
<a href="?sect=home">Home</a><br>
<a href="?sect=test">Test</a><br>
<a href="?sect=test2">Test2</a><br>
<a href="?sect=test3">Test3</a><br>
<a href="?sect=test4">Test4</a>
</body></html>

Atomic-Design
4-15-02, 09:04 PM
What's wrong with it?

xero-infinity
4-15-02, 09:09 PM
All of them show. I just want one of them to show at a time.

MannInc
4-15-02, 09:36 PM
I'm no PHP expert, but you might wish to set $sect to equal something like :

if ($sect != "") {
include("$sect.txt");

Hope this helps!

xero-infinity
4-15-02, 09:41 PM
Nah, did the same thing.

MannInc
4-15-02, 09:53 PM
You might need to have it somehow read in the sect and place it in $sect and than have it redirect to the right file.

xero-infinity
4-15-02, 10:26 PM
the sect.txt you mean? er... man, I don't understand what your sayin.

ffejy
4-15-02, 11:23 PM
I'm not exactly sure what you are trying to do... But all that code you have there could be compressed into the following without changing anything...

if ($sect) {
include("$sect.txt");
} else {
include("home.txt");
include("test.txt");
include("test2.txt");
include("test3.txt");
include("test4.txt");
}
?>

If you are trying to include the file with the name $sect.txt, then one of these if-else statements should be plenty, as shown above. I'm not exactly sure what you want to display if there is no value for $sect, but from your example I assume it is to include all 5 files.

Perhaps you can clarify exactly what you are trying to accomplish here...

Jeff

xero-infinity
4-16-02, 05:26 PM
yeah, that worked. Thanks