Jay Kapoor
Jay Kapoor

Reputation: 21

php- how to show extra whitespaces on mysql db output?

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.

Upvotes: 0

Views: 89

Answers (1)

user2010925
user2010925

Reputation:

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.

Upvotes: 1

Related Questions