Solved

Wrapping PHP

Posted on 2012-04-07
5
231 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
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 109

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

803 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