php - Title tag not displaying as expected

895

I try to style the rows with a CSS class. Now the MySQL data appears on the page, and not in the title tag anymore.

Where is the mistake?

Screenshot

<a href="" title="

<?php
$abfrage = "SELECT * FROM tester";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))
{
?>
<p><span class="qtip-big"><?php echo $row->Name; ?></span></p>

<p><?php echo $row->Beschreibung; ?></p>

<?php
}
?>

">Testlink</a>

The text appears on the page and not inside of the tooltip.

695

Answer

Solution:

Your html is all wrong :) Your code does something like this:

<a title="<p>paragraph</p>" > anchor </a>

Html element are not allowed in attributes (title is an attribute, so is href / src/ alt etc)

To get multiple lines, you can do this:

<a title="Line1 \nline2" > anchor </a>

I've added\n which is a character for newline. Also not that 'line2' is directly attached. Though this looks stupid, it prevents a whitespace bevore 'line2'

If you have htmlerrors, you should try an html-validator, this will return the errors you have in html

357

Answer

Solution:

Remove the paragraph tags from your title attribute.

69

Answer

Solution:

first off all you should not put HTML tags inside the title. Second of all why are you putting the php scripts inside there in such a messed up way. It reduces readability. Grab the SQL contents before you put it in the title.

<?php
    $abfrage = "SELECT * FROM tester";
    $ergebnis = mysql_query($abfrage);
    while($row = mysql_fetch_object($ergebnis)){
        $name=$row->name;
        $Bech=$row->Beschreibung;
    }
?>

<a href="" title="<?=$name?> <?=$Bech?>">Test Link</a>

Hope this helps.

48

Answer

Solution:

<?php
$abfrage = "SELECT * FROM tester";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_array($ergebnis))
{
$Name=$row['Name'];
$Beschreibung=$row['Beschreibung'];
}
<a href='link' title='<? echo $Name?> <? echo $Beschreibung?>'>link</a>
960

Answer

Solution:

You must escapse the contents of your html attributes. Easiest way it to use urlencode.

 echo urlencode("<p>".$row->Name."</p><p>".$row->Beschreibung."</p>");

It's worth noting as well that html is not natively going to render within a title attribute and you must use a javascript tool tip library to get this to work as you are envisioning.

People are also looking for solutions to the problem: mysql - PHP encoding issues

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.