Trouble getting the path correct

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjl
Forum Newbie
Posts: 13
Joined: Wed May 14, 2008 12:31 am

Trouble getting the path correct

Post by jjl »

~pickle: Please use proper code tags "code=php", "code=html", etc

I have a fn() that creates menus from a database file. The code is simple

Code: Select all

while ($sql = mysql_fetch_object($result)) 
                {
                $filename = $sql -> Link;
                $Text = $sql -> Title;
                
                if ($menuname == "Gallery")
                    {
                    $image = $sql ->Image;
                    $CssClass = $sql ->CssClass;
                    echo "<li class = $CssClass >";
                    echo "<a href= $filename ><img src = $image ></a>"; 
                    }
                    else {
                    echo '<li>';
                    echo "<a href= $filename >$Text</a>"; 
                    }
                echo '</li>';
                }
The trouble is that if I call it from a different directory I will end up with a different path. For example
-- called from dirA I end up with the link being http://www.xyz.com/dirA/filename.php
-- called from dirB I end up with the link being http://www.xyz.com/dirB/filename.php
the database just has filename.php, no path info at all.

I just want the path to be static so I can just load these menus from anywhere. Any suggestions appreciated. I am new at this stuff so sorry if it is beginner type question.

~pickle: Please use proper code tags "code=php", "code=html", etc
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: Trouble getting the path correct

Post by vargadanis »

These are called relative links. They only point to the file and not to the entire URL of it. If you want to call the file whereever it is you need to give an absolute path starting with http://
eg:

Code: Select all

echo "<a href = \"http://ursite.com/\"" . $filename . ">asd</a>"
Post Reply