English 中文(简体)
PHP 新线
原标题:PHP new line and not working
  $rows = mysql_num_rows($result) ;
  for ($j=0 ; $j < 3 ; $j++) {
  for ($i=0 ; $i < 3 ; $i++) {
    $row = mysql_fetch_array($result) ;
    echo  <a href="image2.php?id= .$row[ ID ]. "> ."<img src= ".$row[ Image ]."  />". </a>  ;

  }
   echo "
";
  }

The code displays three groups of three images. My understanding was that and (double quotes) should create a new line. However it is just inserting a space between the images. Is the way am callign wrong or is it am using the wrong code to isneert a new line (line break)

实例(图1):

Without echo : ######### With echo : ### ### ###

最佳回答

Your echo " "; is outside the loop. Move it inside the loop.

而且,如果你希望浏览器能看到线上的差异,你也应印刷<条码>和代号;。

  $rows = mysql_num_rows($result) ;
  for ($j=0 ; $j < 3 ; $j++) {
  for ($i=0 ; $i < 3 ; $i++) {
    $row = mysql_fetch_array($result) ;
    echo  <a href="image2.php?id= .$row[ ID ]. "> ."<img src= ".$row[ Image ]."  />". </a>  ;
  }
    echo "<br />
";    
  }
问题回答

Whitespace is not displayed verbatim when it s part of HTML text. and are not universal constants; they are just characters, and it s up to whatever program consumes them to decide what to do with them.

您应使用<br>

You need:

echo  <br /> ;

而不是:

echo "
";

You can also consider setting a proper header Exmaple:


$data = [
    [1,2,3],
    [4,5,6],
    [7,8,9]
];
header("Content-Type: text/plain");
foreach($data as $row){
    echo implode( , , $row) . "
";
}





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签