Question

I got one Problem and have no Idea how to solve this. I got following PHP/MySQL table on one of my sites:

   <table class="table table-striped">
     <thead>
       <tr>
         <th>UUID</th>
         <th>Coins</th>
         <th>Name</th>
         </tr>
       </thead>
     <tbody>
    <?php
    error_reporting(E_ALL);
    define ( 'MYSQL_HOST',      'localhost' );
    define ( 'MYSQL_BENUTZER',  'USER' );
    define ( 'MYSQL_KENNWORT',  'PASSWORD' );
    define ( 'MYSQL_DATENBANK', 'DATABASE' );
    $db_link = mysqli_connect (
                         MYSQL_HOST, 
                         MYSQL_BENUTZER, 
                         MYSQL_KENNWORT, 
                         MYSQL_DATENBANK
                        );

    $sql = "SELECT * FROM TABLE";
    $db_erg = mysqli_query( $db_link, $sql );
    if ( ! $db_erg )
    {
      die('Ungültige Abfrage: ' . mysqli_error());
    }
    while ($zeile = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))  
    {
           echo "<tr>";
           echo "<td>". $zeile['1'] . "</td>";
           echo "<td>". $zeile['2'] . "</td>";
           echo "<td>". $zeile['3'] . "</td>";
           echo "</tr>";
           }
           mysqli_free_result( $db_erg );
           ?>
  </tbody>
 </table>

Now I want to make a 4th row with a dynamic link in it, kinda like this:

echo "<td>". <a href="http://mysite.tld/test/blabla/$zeile['3']">$zeile['3']<a> . "</td>";

But that does not work, what am I doing wrong?

Was it helpful?

Solution

You're not enclosing the link tag in quotes. So PHP is probably giving you parser errors when it encounters the first < because that character doesn't mean anything to PHP in that context. You need to wrap the added HTML in quotes just like the HTML you already have. Something like this:

echo "<td><a href=\"http://mysite.tld/test/blabla/" . $zeile['3'] . "\">" . $zeile['3'] . "<a></td>";

In fact, since variable names are expanded in double-quoted strings, you can simplify:

echo "<td><a href=\"http://mysite.tld/test/blabla/$zeile['3']\">$zeile['3']<a></td>";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top