0

Echo works fine at other lines But when i try to add tag to this table, i see that tags placed out of the tag.

    <table>
<th style="cursor:pointer;border-radius:5px 0px 0px 0px;">Başlık</th>
<th style="cursor:pointer;">Başlatan</th>
<th style="cursor:pointer;border-radius:0px 5px 0px 0px;">Tarih</th>

$sonuc = mysql_query("select A.subject, A.poster_name, A.poster_time, A.id_msg, A.id_topic, B.id_first_msg, B.id_member_started from smf_messages A, smf_topics B WHERE A.id_msg = B.id_first_msg ORDER BY id_topic DESC LIMIT 10");

if(mysql_num_rows($sonuc)!=0)
{
    while($oku = mysql_fetch_object($sonuc))
    {
        echo '<tr id="iceriktablo" style="cursor:pointer;margin-top:0;margin-bottom:0;">';
        echo '<a href="forum/index.php?topic='. $oku->id_topic .'"><td style="font-size:13px;font-weight:bold;">';
        echo $oku->subject;
        echo '</td></a>';
        echo '<a href="forum/index.php?topic='. $oku->id_topic .'"><td style="font-size:13px;font-weight:bold;"><center><b>';
        echo $oku->poster_name;
        echo '</b></center></td></a>';
        echo '<td style="font-size:13px;font-weight:bold;"><center><b>';
        $zaman = $oku->poster_time;
        echo gmdate("d-m-Y\ H:i:s", $zaman);
        echo '</b></center></td></tr></a>';
    }
}else{
    echo "Hiçbir kayıt bulunamadı!";
}
mysql_close($conn);
?>

</table>

result as inspect element: http://puu.sh/qed4c/7b04611347.png result: enter image description here filename: index.php

Sezer Toker
  • 23
  • 11
  • 2
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 25 '16 at 20:32
  • Where you want to add tag? – Nasir Jul 25 '16 at 20:36
  • But my php version is 5.3.29 @Nasir i wanna add tag like this ... – Sezer Toker Jul 25 '16 at 20:38
  • 1
    Don't apply link on tr or td but apply on some text inside tds – Nasir Jul 25 '16 at 20:41
  • @Nasir but i wanna make tr as link :( – Sezer Toker Jul 25 '16 at 20:43
  • 1
    @Nasir In that's case you need to bind a click event to the `tr` – Aaron Jul 25 '16 at 20:46
  • @Aaron thank you. This is the solution i seek for. How i can close the topic? – Sezer Toker Jul 25 '16 at 20:47
  • The only [permitted content](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr) of a `` is `` or ``. You can make your `` act like a link using javascript by attaching a click event handler. And your PHP version has been [end of life](http://php.net/supported-versions.php) for quite a while. – Don't Panic Jul 25 '16 at 20:47
  • 1
    @SezerToker First of all, `id="iceriktablo"` in a while-loop is a bad idea – Aaron Jul 25 '16 at 20:49
  • @Aaron why is it? Should i add style=".." ? – Sezer Toker Jul 25 '16 at 20:53
  • 1
    @SezerToker `id` should be unique to the entire document. Simply put, one-to-one mapping for a given `id` and an element. In the while loop, you can have one to many. Use `class` instead – Aaron Jul 25 '16 at 20:54
  • Thank you, I will do that @Aaron I learned much from this site's society. – Sezer Toker Jul 25 '16 at 20:58
  • @SezerToker Chances are if you didn't know that fact, you are overstepping your boundaries and should go back to reviewing the basics before making database calls. – Aaron Jul 25 '16 at 21:00
  • I am trying to learn everything i see but there is no proper lessons on web(in my language) to teach the subtleties of html, php or sql. So i am trying to learn with trying if fails asking. Sorry if i bother you with my questions. I will try to search deeply next time. – Sezer Toker Jul 25 '16 at 21:05
  • @SezerToker You're not bothering anyone. As for your immediate problem, I believe this would be the easiest way. https://api.jquery.com/click/ – Aaron Jul 25 '16 at 21:09

2 Answers2

1

Your HTML is invalid:

    echo '<a href="forum/index.php?topic='. $oku->id_topic .'"><td style="font-size:13px;font-weight:bold;"><center><b>';
    echo $oku->poster_name;
    echo '</b></center></td></a>';

The A-tag isn't allowed to wrap TD (and of course some more). I guess the browser corrected that automatically.

Honk der Hase
  • 2,459
  • 1
  • 14
  • 26
0

Tag A is not a part of a table to it will be always placed out of it. You can't do somethig like this

<table>
    <tr>
        <a><td></td></a>
    </tr>
</table>

You should place your A tag inside TD or TH tag.

zajonc
  • 1,935
  • 5
  • 20
  • 25