3
<input type="text" list="req" name="req" style="width:350px; height:70px;"><datalist id="req">
    <option value=""><option>
    <?php  while($getreq = $requirements->fetch_array()){ ?>
    <option><?=$req = preg_replace("/\r\n|\r|\n/",'<br/>',$getreq['req']);?></option>  
    <?php  } ?>
</datalist>

I have this query from database with 50rows, some rows the text have breakline. But the thing is when I check the datalist the breakline doesn't work.

ex:

No1 - Visible Fracture(s) of the center member.2 - The center member separates.3 - Loses air pressure in 1 minute.

but in my database it's like this.

No
1 - Visible Fracture(s) of the center member.
2 - The center member separates.
3 - Loses air pressure in 1 minute.

Any idea how to solve my problem.?

   Database
   ID     Req
   1      Bead Unseating Test Min. 9100 N
   2      Breaking Energy Test Min. 113 N.m. (J)
   3      No<br/>1 - Visible Fracture(s) of the center member.<br/>2 - The center member separates.<br/>3 - Loses air pressure in 1 minute.


  Must be Output in datalist or Select Option (Dropdown Menu)
  Bead Unseating Test Min. 9100 N
  Breaking Energy Test Min. 113 N.m. (J)
  No
  1 - Visible Fracture(s) of the center member.
  2 - The center member separates.
  3 - Loses air pressure in 1 minute.
  • *nl2br()* ? http://php.net/manual/en/function.nl2br.php ... not sure it'll help inside an ` – CD001 Jan 09 '17 at 16:51
  • it doesn't work @CD001 so any dropdown list i can use to have this work? – Genina Anne Gabuten Jan 09 '17 at 16:58
  • The PHP might be working, view source, but you can't put any other markup inside ` – CD001 Jan 09 '17 at 17:00
  • ... I've no idea whether this will work either but try leaving the newline characters as they are but apply `pre` styling to the option, e.g. `` – CD001 Jan 09 '17 at 17:03
  • yes seems
    doesn't work in Select Option and Datalist. I have no idea how to make it work. sadly
    – Genina Anne Gabuten Jan 09 '17 at 17:05
  • still not work @CD001 – Genina Anne Gabuten Jan 09 '17 at 17:08

1 Answers1

1

Probebly you need nl2br() instead of preg_replace()

Check PHP.NET manual page Here.

Edited Answer

<option> does not accept
so if you want

<select>

<option>1</option>

<option>2</option>

<option>2</option>

</select>

Here you need to make change

<?
$optarray  = explode("<br>", $getreq);

foreach($optarray as $optval){ ?>
<option><?= echo $optval; ?></option>
<? } ?>
php-coder
  • 955
  • 1
  • 12
  • 23
  • ok, this seems that you are passing data in single – php-coder Jan 09 '17 at 17:07
  • yes the datalist and select option bypass the
    and all they goes to same line. I keep searching still I can't find any solution.
    – Genina Anne Gabuten Jan 09 '17 at 17:10
  • doesnt work, btw No1 - Visible Fracture(s) of the center member.2 - The center member separates.3 - Loses air pressure in 1 minute. this is in 1row only – Genina Anne Gabuten Jan 09 '17 at 17:26
  • Can you show me how your data saved in database? and also Final output you want? – php-coder Jan 09 '17 at 17:27
  • I have made small change in my explode () you can try that. After explode () you will get an array of all your result and than you can use foreach() loop to have – php-coder Jan 10 '17 at 02:34
  • It works BUT, No 1 - Visible Fracture(s) of the center member. 2 - The center member separates. 3 - Loses air pressure in 1 minute. this 1 row in database Became 3Rows. What Im trying to output is for example. I select "No" the first line it will display all the content. I don't want it to separate and make it array – Genina Anne Gabuten Jan 10 '17 at 06:06