如何从数据库中准确检索数据,包括行空格和输入


how to retrieve data exactly from database, including the line spaces and enters?

我有一个PHP文件,它从我的SQL数据库中检索数据并且工作得很好..但它没有以相同的结构显示..它只是将所有内容转储一个段落..我可以知道如何准确地检索它与所有空格并输入..?

菲律宾比索

    <div class="maindiv">
    <div class="divA">
    <div class="title">
    </div>
     <div class="divB">
     <div class="divD">
      <p>Click On Menu</p>
         <?php
         $connection = mysql_connect("localhost", "root", "");  
          $db = mysql_select_db("SBI", $connection); 
             $query = mysql_query("select * from recipes", $connection);
             while ($row = mysql_fetch_array($query)) {
               echo  "<b><a href='"CookWhatLahSBIAfter.php?id=  {$row['id']}'">{$row['name']}</a></b>";
          }
                ?>
          </div>
            <?php
              if  (isset($_GET['id'])) {
        $id = $_GET['id'];
          $query1 = mysql_query("select * from recipes where id=$id", $connection);
       while (  $row1 = mysql_fetch_array($query1))  {
       ?>
      <div class="form">
          <h2>---You can cook..---</h2>
            <h1><span title="Recipe Name" style ="color: #0c0f44; font-size:  15pt;text-decoration:underline;">Name:</span><?php echo $row1['recipename']; ?><br><br></h1>
        <span title="Recipe Ingredients" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo  $row1['ingredients']; ?><br><br>
        <span title="Recipe Steps" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe']; ?><br><br><br>
          <h1><span title="Recipe Name" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename1']; ?><br><br></h1>
         <span title="Recipe Ingredients"  style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients1']; ?><br><br>
         <span title="Recipe Steps" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe1']; ?><br><br><br>
         <h1> <span title="Recipe Name" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename2']; ?><br><br></h1>
       <span title="Recipe Ingredients"  style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients2']; ?><br><br>
       <span title="Recipe Steps" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe2']; ?><br><br><br>
       <h1><span  title="Recipe Name" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename3']; ?><br><br></h1>
         <span title="Recipe Ingredients"  style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients3']; ?><br><br>
        <span title="Recipe Steps" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe3']; ?><br><br>
        <h1><span title="Recipe Name" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Name:</span> <?php echo $row1['recipename4']; ?><br><br></h1>
        <span title="Recipe Ingredients"  style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Ingredients:</span> <?php echo $row1['ingredients4']; ?><br><br>
         <span title="Recipe Steps" style="color: #0c0f44; font-size: 15pt;text-decoration:underline;">Recipe:</span> <?php echo $row1['recipe4']; ?><br><br><br>

    </div>
   <?php
      }
     }
      ?>
     </div>
      </div>
      </div>
       <?php
     mysql_close($connection);  
      ?>

这就是我的MySql的样子。这就是它在网站中的样子。

我认为您正确获取了数据,但问题是数据库本身中的数据。我会解释一下,对于 HTML,"输入"没有任何意义,但<br/>意味着什么。

所以你要做的是用你想要的格式的HTML标签将数据保存在数据库中,而不是"输入"你需要<br/>,而不是"粗体"你需要<b>,而不是"空格"你需要&nbsp等等......

最简单的方法是使用所见即所得(所见即所得)编辑器插件来保存信息。一个好的是CKEditor。去看他们的演示。 更改一些文本和内容,然后单击"HTML源代码"按钮,它将显示数据库中应该包含的内容,而不是"纯文本"

我相信您要显示的哪个字段是

<?php echo nl2br($row1['recipe4']); ?>