Solved

Wrapping PHP

Posted on 2012-04-07
5
228 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

18 Experts available now in Live!

Get 1:1 Help Now