Jump to content

Php Cooding with space and new line (Help request)


lasse48

Recommended Posts

hello

i cant find any help on getting the echo output with spaces and on ea lines, :(

Exampled is in picture ;D

 


<?php

include("img/troops/units_id.php");

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("travian", $con);



// Legionnaire

$result = mysql_query("SELECT * FROM s1_units WHERE u1>'0'");
while($row = mysql_fetch_assoc($result)) 
   {
      echo "<img src=\"img/troops/u1.jpg\" border=0>";
      echo $row[u1];
      echo $units_id_1;

   }



// Praetorian

$result = mysql_query("SELECT * FROM s1_units WHERE u2>'0'");
while($row = mysql_fetch_assoc($result)) 
   {
      echo "<img src=\"img/troops/u2.jpg\" border=0>";
      echo $row[u2];
      echo $units_id_2;

   }


?>

 

Thanks

 

[attachment deleted by admin]


<?php

include("img/troops/units_id.php");

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("travian", $con);

echo "<table cellpadding='3' cellspacing='3'>";

// Legionnaire

$result = mysql_query("SELECT * FROM s1_units WHERE u1>'0'");
while($row = mysql_fetch_assoc($result)) 
   {
      echo "<tr><td><img src=\"img/troops/u1.jpg\" border=0></td>";
      echo "<td>".$row[u1]."</td>";
      echo "<td>".$units_id_1."</td></tr>";

   }



// Praetorian

$result = mysql_query("SELECT * FROM s1_units WHERE u2>'0'");

while($row = mysql_fetch_assoc($result)) 
   {
      echo "<tr><td><img src=\"img/troops/u2.jpg\" border=0></td>";
      echo "<td>".$row[u2]."</td>";
      echo "<td>".$units_id_2."</td></tr>";

   }

echo "</table>";

?>

Try changing your outputs to build tables instead of just echoing the data and see if it looks better. This example should paste right in to the second display block, but you'll need to modify the first one to match.

 

$result = mysql_query("SELECT * FROM s1_units WHERE u2>'0'");
echo "<table>";
while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><img src=\"img/troops/u2.jpg\" border=0></td>";
echo "<td>{$row[u2]}</td>";
echo "<td>{$units_id_2}</td>";
echo "</tr>";
}
echo "</table>";

Thanks alot for the were fast reply  ::)  // msaz87 and Pikachu2000  ::)

 

Pikachu2000 your code sample gets the job done!  :o

 

Pikachu2000 if you got time , do you got any ideas how to get the output on same tabel line , dont how to explaine it, so i paint it ;D (you can see it in picture)

 

thanks alot guys.

 

 

[attachment deleted by admin]

Yes, you can just leave the initial <table> tag open until after the second table is completed.

 

In other words, from the first block, remove (or comment out) the closing echo "</table>";

And the second block, remove the opening echo "<table>";

Thanks agian ;D    iam alitte confused , when i add ALIGN="right" to <td>  (<td ALIGN="right">)

The page just go out in error with northing on :(

 

I feel like i am the one in the vid link you posted , hehe ;D    (************ Please, I beg of you, don't be the kid in this video! (NSFW) ************)

 


<?php

include("img/troops/units_id.php");

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("travian", $con);





// Legionnaire Unit Id 1

$result = mysql_query("SELECT * FROM s1_units WHERE u1>'0'");
echo "<table>";
while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><img src=\"img/troops/u1.jpg\" border=0></td>";
echo "<td ALIGN="right">{$row[u1]}</td>";
echo "<td>{$units_id_1}</td>";
echo "</tr>";
}




// Praetorian Unit Id 2

$result = mysql_query("SELECT * FROM s1_units WHERE u2>'0'");

while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><img src=\"img/troops/u2.jpg\" border=0></td>";
echo "<td ALIGN="right">{$row[u2]}</td>";
echo "<td>{$units_id_2}</td>";
echo "</tr>";
}
echo "</table>";

?>

 

 

 

Because the string is in double quotes, you have to escape any double quote you use within the string by preceding it with a backslash.

 

echo "<td ALIGN=\"right\">{$row[u2]}</td>";

thanks were much dude  ::)

 

No errors left  :D

help finish  ;D

 

Final code:

<?php

include("img/troops/units_id.php");

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("travian", $con);





// Legionnaire Unit Id 1

$result = mysql_query("SELECT * FROM s1_units WHERE u1>'0'");
echo "<table>";
while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><img src=\"img/troops/u1.jpg\" border=0></td>";
echo "<td ALIGN=\"right\">{$row[u1]}</td>";
echo "<td>{$units_id_1}</td>";
echo "</tr>";
}




// Praetorian Unit Id 2

$result = mysql_query("SELECT * FROM s1_units WHERE u2>'0'");

while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td><img src=\"img/troops/u2.jpg\" border=0></td>";
echo "<td ALIGN=\"right\">{$row[u2]}</td>";
echo "<td>{$units_id_2}</td>";
echo "</tr>";
}
echo "</table>";

?>

 

 

 

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.