Solved

Wrapping PHP

Posted on 2012-04-07
5
223 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
Comment Utility
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
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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
Comment Utility
This worked ok.  Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now