Domanda

I am relatively new to php/mysql. I am trying to do carriage returns for this part:

echo "<td colspan='5'>" . nl2br($row['dish_description']) . "</td>";

"dish_description" contains some text which includes "\n" e.g. "Served with salad and mint sauce. \n Contains beef." In the MySQL database however I cannot display the carriage return.

    <?php
    require_once 'login.php';
    $con = mysql_connect($db_hostname, $db_username, $db_password);
    mysql_select_db($db_database) or die("Unable to select database". mysql_error());

    $result = mysql_query("SELECT * FROM `dishes` ORDER BY `dishes`.`dish_id` ASC LIMIT 0 , 200");

    echo '<table align="center">
    ';

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td style='width: 60px'></td>";
    echo "<th style='width: 100px'>Dish No</th>";
    echo "<td style='width: 70px'>" . $row['dish_id'] . "</td>";
    echo "<th style='width: 100px'>Dish Name</th>";
    echo "<td style='width: 120px'>" . $row['dish_name'] . "</td>";
    echo "<th style='width: 120px'>Dish Price</th>";
    echo "<td>£" . $row['dish_price'] . "</td>";
echo "</tr>";

echo "<tr>";
    echo "<td style='width: 75px'></td>";
    echo "<th style='width: 100px'>Vegetarian</th>";
    echo "<td style='width: 70px'>" . $row['dish_vegetarian']   ."</td>";
    echo "<td style='width: 100px'></td>";
    echo "<td style='width: 70px'></td>";
    echo "<th style='width: 120px'>Contains Nuts</th>";
    echo "<td style='width: 120px'>" . $row['dish_nuts']   ."</td>";
echo "</tr>";
echo "<tr>";
    echo "<td style='width: 75px'></td>";
    echo "<th style='width: 100px'>Information</th>";
    ***echo "<td colspan='5'>" . nl2br($row['dish_description']) . "</td>";***
echo "</tr>";
echo "<tr height='10px'>";
    echo "<td style='width: 75px'></td>";
    echo "<td style='width: 100px'></td>";
echo "</tr>";
    }
    echo "</table>";

    mysql_close($con);
?>
È stato utile?

Soluzione

In my opinion if you echo it as HTML you can just add <br> tags to your records in database.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top