Solved

Wrapping PHP

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
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.

730 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