Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/151988-echo-spacing/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798176
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/151988-echo-spacing/#findComment-798185
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.