ian
ian

Reputation: 12335

code prepending url to link

My PHP is prepending the pages URL into my link for some reason.

Links that should have a value of # come out as mysite.com/url_the_page/page.php# and idea what would cause this?

echo'<a href="#" id="bb">click me</a></span>';
echo '<a href="#" id="song_'. $row[id].'">';
echo $artist_title;
echo '</a></span>';`

Full code:

while ($row = mysql_fetch_array($query))
    {

        if ($row[sourcefile] !== NULL )
        {


            echo '';


            if ( $row[artist] !== NULL && $row[title] !== NULL)
            {
                $artist_title = $row[artist] . ' - ' . $row[title];
            }
            else
            {
                $artist_title = $row[originalfilename];
            }



            echo "<a href=http://".$row[link].' target="_blank">LINK</a> - ';

            if ( $row[listened] == 0)
            {
                $link_class = "unlistened";
            }
            else
            {
                $link_class = "listened";
            }

            $size = $row[size];
            $size = round(($size / 1000000),2);

            if ( $size > 30 )
            {
                echo '<font color="red">MIX </font>';
            }

            echo '<span id="'.$row[id].'" class="'.$link_class.'">';                

            echo '<a href="#" id="song_'. $row[id].'">';
            echo $artist_title;
            echo '</a></span>';

            echo ' - ';

            //turn size into MB
            $size = $row[size];
            $size = round(($size / 1000000),2);

            //if the song is smaller than a certain size display the size as red.   
            if ( $row[size] < 1500000)
            {
                echo '<font color="red">';
                echo $size;
                echo '</font>';
            }
            else
            {
                //echo $row[size];
                echo $size;
            }

            echo 'MB<br>';

        }
    }

Upvotes: 1

Views: 210

Answers (2)

Christophe
Christophe

Reputation: 4828

As far as I know this is a normal behaviour, if you have a link with name categories, eg:

<a name="categories"></a>

Then you would link to that section of the page using the following url

mysite.com/index.html#categories

Upvotes: 1

Pekka
Pekka

Reputation: 449613

This has nothing to do with PHP, but is the default behaviour of your browser.

# is not a valid URL, but a so-called Fragment Identifier. It has a special meaning in URLs, directing the browser to look for an anchor of that name in the target document. A URL pointing to # only will point to the current document's beginning.

I'm not sure what you want to do, but URLs must not contain this character in their address part.

Upvotes: 5

Related Questions