Page 1 of 1

[solved] simple isset problem

Posted: Sun Sep 03, 2006 1:08 pm
by seeker2921
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello, i've pretty much forgoten everything i knew about php since i havent used it in years. i know this is simple but i was woundering if someone could help me out.. heres what im trying to do

myurl.com/index.php?id=gallery

now when this is entered the page i need it to include a seperate php file into my template heres the code ive tried

Code: Select all

<?
if(!isset($id)){
include('/home/stephen/public_html/site/blog/index.php');
}
elseif($id==($links))
{
include('$links');
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Sep 03, 2006 1:15 pm
by jayshields
Maybe you want to check against $_GET['id'] rather than $id.

Posted: Sun Sep 03, 2006 1:18 pm
by seeker2921
i tried setting $id=($_get['id'])} in attempt to correct it earlyer. didnt work, see the first half of the code works fine. its when i add the id in the url it mess' up.

Posted: Sun Sep 03, 2006 1:24 pm
by feyd
Useful Posts references a thread you may find of interest.

Posted: Sun Sep 03, 2006 1:37 pm
by seeker2921
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


thanks feyd, i went there and found a useful post. i tried this code

Code: Select all

<?
if (in_array($_GET['id'],$url)) {
   include $_GET['id'];
} else {
   include('/home/stephen/public_html/site/blog/index.php');
} 
?>
now what happens is regrdless if i go to domain.com/index.php or domain.com/index.php?id=gallery it shows the blog


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 04, 2006 4:59 am
by seeker2921
i know this is a simple problem.. i just dont see what im doing wrong, ive looked at php.net and tried stuff from there still no luck..

Posted: Mon Sep 04, 2006 8:17 am
by feyd
What is $url?

Posted: Mon Sep 04, 2006 11:56 am
by seeker2921
$url is my array that has all the locations of the include files

Posted: Mon Sep 04, 2006 12:00 pm
by RobertGonzalez
Will this work for you at all?

Code: Select all

<?php
$id = 0;
if (isset($_GET['id']))
{
    $id = $_GET['id'];
}

if (0 != $id) {
    include '/home/stephen/public_html/site/blog/index.php';
} else {
    include $links;
}
?>

Posted: Mon Sep 04, 2006 12:14 pm
by seeker2921
i tired it, no luck. I then tried this code it did fine the first part but when i added the main.php?id=gallery it gave me this error message

Warning: main($links): failed to open stream: No such file or directory in /home/stephen/public_html/main.php on line 160

Warning: main($links): failed to open stream: No such file or directory in /home/stephen/public_html/main.php on line 160

Warning: main(): Failed opening '$links' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/stephen/public_html/main.php on line 160

heres the code i used

Code: Select all

<? 
if(!isset($id)){
include('/home/stephen/public_html/site/blog/index.php');
} 
else 
{ 
    for($i=0; $i<count($url); $i++) 
    { 
        if($id==$links[$i]) 
        { 
            include('$links');
            break; 
        } 
    } 
} 
?>

Posted: Mon Sep 04, 2006 12:20 pm
by seeker2921
i messed around with what i had up above and now it works.. thanks for the help guys..

heres the code that works

Code: Select all

<?
if(!isset($id)){
include('/home/stephen/public_html/site/blog/index.php');
}
else
{
    for($i=0; i<count($links); $i++)
    {
        if($id==$links[$i])
        {
            include($url[$i]);
            break;
        }
    }
}
?>

Posted: Mon Sep 04, 2006 12:21 pm
by feyd
Single quote strings are string literals. They do not parse any variables inside of them. In this particular case, you don't need quotes at all. However, apparently $links is an array.