joe1986 Posted March 31, 2009 Share Posted March 31, 2009 Hi there, I think its a bit of a simple one really but im a PHP newbie. Im trying to put a space in between the output values (shown below) and I thought the ." ". in the middle would solve this problem, but it turns out not; and im pulling my hair out. The code I have for output reads: while ($row = mysql_fetch_array($result)) { echo " ".$row{'subject'}." ".$row{'data'}."<br>"; and the output is displayed as: "Subject Data" I want to put more spaces in between these two values, e.g. "Subject _________ Data" (obviously without the _) Could anybody please help me? Cheers, Joe Quote Link to comment https://forums.phpfreaks.com/topic/151988-echo-spacing/ Share on other sites More sharing options...
.josh Posted March 31, 2009 Share Posted March 31, 2009 not a php issue... thats just how html renders it. Need to use the html code or the pre tag or add some other tag around your items and add padding or margin with css. Quote Link to comment https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798175 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 For it to display on a webpage, you would need to use and strpad will be your best friend. If it is to be displayed in a text file, strpad is still the way, but instead of just use the regular space character. echo " ". strpad($row{'subject'}, 10, " ") . $row{'data'}."<br>"; EDIT: I remember having issues with this using the so I am not sure if that will work in this case. If not just manually add them in. Quote Link to comment https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798176 Share on other sites More sharing options...
joe1986 Posted March 31, 2009 Author Share Posted March 31, 2009 Thanks for the quick reply. It is to be displayed on a webpage within a html table. Im not quite sure where to insert the or how to manually add the space in. I tried the strpad code you suggested, but no luck. any suggestions? thanks again for the reply. Joe For it to display on a webpage, you would need to use and strpad will be your best friend. If it is to be displayed in a text file, strpad is still the way, but instead of just use the regular space character. echo " ". strpad($row{'subject'}, 10, " ") . $row{'data'}."<br>"; EDIT: I remember having issues with this using the so I am not sure if that will work in this case. If not just manually add them in. Quote Link to comment https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798185 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 echo " ".$row['subject']." ".$row['data']."<br>"; Will produce 3 spaces between the subject and data. Also note that you have {} instead of [ and ] Arrays should be called using the [ isntead of {. Quote Link to comment https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798187 Share on other sites More sharing options...
joe1986 Posted March 31, 2009 Author Share Posted March 31, 2009 Ahhh right, I get it. Thanks very much for helping, despite it not being a PHP problem. Cheers, Joe Quote Link to comment https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798188 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.