Page 1 of 1

Trouble getting the path correct

Posted: Sun Jun 01, 2008 4:53 pm
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

Re: Trouble getting the path correct

Posted: Tue Jun 03, 2008 8:13 am
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>"