0

I am saving records like below in my MySQL database:

Name: Hello World                               Age: 17
Ref. by: Lorem Ipusm                            Sample: Blood

                         www.domainname.com

Investigations    Results            Units          N.Ranges
Haemoglobin       14.5               Gms%.          {13-18}

you might have got an idea ,i am doing the following:

$data = mysqli_real_escape_string($dbc, nl2br($_POST['data']));
$sql = "INSERT INTO data (Data) VALUES ('$data')";
$exec = mysqli_query($dbc, $sql);

But when I am displaying the output, it removes all the extra whitespaces and shows output like:

Name: Hello World Age: 17
Ref by.: Lorem Ipsum Sample: Blood
www.domainname.com
Investigation Results Units N.Ranges
Haemoglobin 14.5 Gms%. {13-18}

All the alignment is messed up, any way to make what I want work? Thanks in advance.

4
  • 2
    Use <pre></pre> tags. Commented Mar 29, 2015 at 0:56
  • @Fred-ii you should answer that in the answer box :) Commented Mar 29, 2015 at 1:03
  • @rezashamdani Thanks for the offer, but I'll pass on this one. Questions like these stand at getting closed, and in such a short "answer", well... the outcome can come as an unexpected surprise ;-) Commented Mar 29, 2015 at 1:05
  • 1
    i cant give you an up-vote if you answer on the comment only. 10+ is better that nothing Commented Mar 29, 2015 at 1:12

1 Answer 1

1

As Fred-ii mentioned, you can wrap your output in <pre></pre> tags. HTML by default ignores any spaces past the first in output. See this for more information.

An alternative could also be replacing all spaces with &nbsp; which will force all the spaces to render out on the page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.