Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何准确地从数据库中检索数据,包括行空间和输入?_Php_Html_Css_Sql - Fatal编程技术网

Php 如何准确地从数据库中检索数据,包括行空间和输入?

Php 如何准确地从数据库中检索数据,包括行空间和输入?,php,html,css,sql,Php,Html,Css,Sql,我有一个php文件,它可以从我的SQL数据库中检索数据,并且工作得非常好。。但它并没有以同样的结构表现出来。。它只是把所有东西都扔到一个段落里。。我可以知道如何准确地检索所有空格和入口吗 Php <div class="maindiv"> <div class="divA"> <div class="title"> </div> <div class="divB"> <div

我有一个php文件,它可以从我的SQL数据库中检索数据,并且工作得非常好。。但它并没有以同样的结构表现出来。。它只是把所有东西都扔到一个段落里。。我可以知道如何准确地检索所有空格和入口吗

Php

    <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);  
      ?>

我相信您想要显示的字段是

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

我认为您获得的数据是正确的,但问题是数据库中的数据本身。我要解释一下,对于HTML来说,enter没有任何意义,但有某种意义

因此,您需要做的是使用HTML标记将数据保存在数据库中,以获得所需的格式,而不是输入所需的内容,而不是粗体所需的内容,而不是所需的空间,等等


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

请停止将其标记为不清楚。。我已经做了研究,问了这个问题你对这个问题的描述太模糊了,不知道你在说什么。详细描述它正在做什么,以及你期望它做什么。另外,只包括相关代码。@EvanCarslake嗨,我实际上是在尝试建立一个网站。。其中,当用户单击配料时。。它应该能够展示他能用它制作的食谱。。工作正常。。但唯一的问题是。。它把所有的东西都写成一段。。我希望它和我在数据库中写的一样。。每种配料和烹饪步骤都有自己的路线。您好,谢谢您的回复。。但这并不是我要找的。。我想。。每种成分都要有各自的特点。。还有烹饪步骤。。我该怎么做?我很高兴这有帮助!