Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wordwrap()

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
GB
Hi all,

Right im having some problems with the wordwrap function.
Basiclly the script below calls from a database which populates the wordwrap function. However its not working. What i want is to limit the amount of characters per line so that my site dosnt stretch apart when the user types some information into the home page edit php script which updates the database table. The home.php which is the script below then calls from the database, however the information called from the database was displayed in long lines which are to big for the page therefore making the site distort. This is why im trying to use the wordwrap function to limit the amount of characters per line.

The problem with the code below is that it dosnt display anything on the page, goto to see the home page, there is nothing on it. How do i get it working so the wordwrap function limits the amount of characters per line to say 100, and also so that it actually displays the data in the database table.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>
<div align="center">
  <table width="724">
    <!--DWLayoutTable-->
    <tr> 
      <td width="100%" height="261" valign="top"><div align="center">

          <p>&nbsp;</p>
          <p><font size="2"><strong>Home of GB Plant and Machinery</strong></font></p>
          <p>&nbsp;</p>
<?

mysql_connect("127.0.0.1","jim11","") or die("Could not connect to SQL server!");
mysql_select_db("gbplantandmachinery") or die("Could not find database!");

$table = "home" ; 
$sql = "select `homeid`, `context` from $table"; 
$rslt = mysql_query($sql);
$input = $result['context'];
$output = wordwrap($input);

while ($result = mysql_fetch_array($rslt))

{     

	 echo "<table width='650'>";
	 echo "<tr>";
	 
     echo '<td><pre><font face="Verdana, Arial, Helvetica, sans-serif">' . $output .'</font></pre></td>
		   
		   </tr>';


}
echo "</table>";

          ?>



        </div></td>
    </tr>
  </table>
</div>
</body>
</html>

Any help is greatly appriciated.

Thanks alot

Jim
 
PHP is outputting what you tell it to. That is $output, which is a wordwrapped string of $input, which is actually $result['context'] at the time that variable is empty. Meaning, it is wordwrapped nothing and that is outputted. Check the code again and you will see that the flow of the code is wrong. Here's what might work better:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>
<div align="center">
  <table width="724">
    <!--DWLayoutTable-->
    <tr>
      <td width="100%" height="261" valign="top"><div align="center">

          <p>&nbsp;</p>
          <p><font size="2"><strong>Home of GB Plant and Machinery</strong></font></p>
          <p>&nbsp;</p>
<?

mysql_connect("127.0.0.1","jim11","") or die("Could not connect to SQL server!");
mysql_select_db("gbplantandmachinery") or die("Could not find database!");

$table = "home" ;
$sql = "select `homeid`, `context` from $table";
$rslt = mysql_query($sql);

while ($result = mysql_fetch_array($rslt))

{     
     $output = wordwrap($result['context']);
     
     echo "<table width='650'>";
     echo "<tr>";
     echo '<td><pre><font face="Verdana, Arial, Helvetica, sans-serif">' . $output .'</font></pre></td>
           
           </tr>';


}
echo "</table>";

          ?>



        </div></td>
    </tr>
  </table>
</div>
</body>
</html>
 
Thanks alot mate, that code above worked a treat,

Ive got it exactly how i want it now.

Again thanks for the help

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top