lasse48 Posted July 12, 2010 Share Posted July 12, 2010 hello i cant find any help on getting the echo output with spaces and on ea lines, Exampled is in picture <?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] Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/ Share on other sites More sharing options...
msaz87 Posted July 12, 2010 Share Posted July 12, 2010 <?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>"; ?> Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085019 Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 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>"; Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085022 Share on other sites More sharing options...
lasse48 Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks alot for the were fast reply // msaz87 and Pikachu2000 Pikachu2000 your code sample gets the job done! 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 (you can see it in picture) thanks alot guys. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085035 Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 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>"; Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085040 Share on other sites More sharing options...
lasse48 Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks agian 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 (************ 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085052 Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 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>"; Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085056 Share on other sites More sharing options...
marcus Posted July 12, 2010 Share Posted July 12, 2010 You could just set a width on the 2nd table cell. <table border="0" cellspacing="3" cellpadding="3"> <tr><td>IMG</td><td style="width:75px;text-align:right">####</td><td>NAME</td></tr> </table> Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085057 Share on other sites More sharing options...
lasse48 Posted July 12, 2010 Author Share Posted July 12, 2010 thanks were much dude No errors left help finish 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] Link to comment https://forums.phpfreaks.com/topic/207532-php-cooding-with-space-and-new-line-help-request/#findComment-1085066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.