Solved

Wrapping PHP

Posted on 2012-04-07
5
249 Views
Last Modified: 2012-06-21
Hi there, I have a 500px wide select statement in PHP, the problem is they show up on one line and sometimes the are too large.  How do I make it so that they can wrap onto a second line, or even show a horizontal scroll bar?  

<select name="selectto" id="select-to" size="8" class="textfield4" tabindex="9">
          <?php
      $sql =mysql_query("SELECT question FROM questions where answer ='' ORDER BY date_asked DESC");
      while ($chk = mysql_fetch_array($sql)) {
          ?>
          <option value="<?php echo $chk['question']; ?>"><?php echo $chk['question']; ?></option>
          <?php
          }
          ?>
</select>
0
Comment
Question by:kesea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37820585
you can use wordwrap function. see below how it can be used.
http://www.w3schools.com/php/func_string_wordwrap.asp
0
 

Accepted Solution

by:
open-source-expert earned 400 total points
ID: 37820636
I think here we cannot use php to wrap as the query result is used to display the options in a select tag. You can show a horizontal scroll bar using html/css. You can put the select tag in a div as something like this

<div style="height:250px; width:500px; overflow-x:scroll ; overflow-y: hidden; >      </div>
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37821462
See http://php.net/manual/en/function.wordwrap.php where you will find some options in the function call that may be useful to you.  The count is a character count, so the exact number of letters you will want to use will be dependent on the font size.  I think this may work for you.  You may have to tinker with the $break parameter.
<select name="selectto" id="select-to" size="8" class="textfield4" tabindex="9">
<?php
$sql = "SELECT question FROM questions where answer = '' ORDER BY date_asked DESC";
$res = mysql_query() or die( "FAIL: $sql<br/>" . mysql_error() );
while ($row = mysql_fetch_assoc($sql)) 
{
    $quv = $row['question'];
    $que = wordwrap($row['question']);
    $opt = '<option value="'
    . $quv
    . '">'
    . $que 
    . '</option>'
    , PHP_EOL
    ;
}
?>
</select>

Open in new window

0
 

Author Comment

by:kesea
ID: 37826232
Ok I tried all of the above solutions and none worked.  When I put the select statement in a DIV it showed me a scroll bar, but it was still off of the screen.  It would only scroll on the select results (but the select results are cut off).  

I tried the 3rd solution which seemed the best, but it is not displaying anything.  How is that statement echoing to the select statement?
0
 

Author Closing Comment

by:kesea
ID: 37826274
This worked ok.  Thanks.
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question