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!

Limit Amount of characters per line when called from mysql db

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
GB
Hi all,

Right my site is database driven,
As u can see the homepage has writing on it, this is called from a database. The user can edit the writing from the admin section by editing whats in the text field and then clicking update. Ive got it so that the text is displayed on the home page in the same format that it is entered into the text field and then the table. This ensures that tabs, spaces and new lines are where the user wants them to be.

However my problem now is that if the user types a line of text into the field box and dosnt press enter once to start a new line the whole site is then stetched apart into bits and completely distorted. So to over come this i have manually started a new line every 16 words of so, so that the text is displayed on the home page without stretching the site. Im woundering if theres anyway to automaticlly do this so the user dosnt have to keep pressing enter every line and a half in the text box.

Would i set a letter column limit in the mysql query that calls the text from the database or would i put a limit on the text field in the admin section some how? Or is there another way of doing it. Basiclly i want it to start a new line and not stetch the site, so i want it to limit the amount of characters per line that it displays on the home page.

This is the code i am using on the home page to call the text from the database and keep it in the format entered by the user in the text field box:

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

while ($result = mysql_fetch_array($rslt))

{     

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


}
echo "</table>";

I done know if its this i need to edit in order to do what im trying to do but i thought id post it anyway.

Im really stuck with this one, so any help would be appriciated.

Thanks alot

Jim
 
Ah right, thats interesting. Ive just read through it and thats what im looking for.

However how would i implement it into the code above i posted? (im guessing it goes on the page which calls the text from the database).
 
wordwrap() returns a string. So instead of using a reference to $result['context'] in your print statement, try wordwrap($result['context'], '<br>')


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ok, ive started implementing wordwrap into my home.php.

However im getting the error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /usr/local/apache2/ on line 44


This is the code im using, can some 1 tell me what is wrong:

Code:
<?

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, '<br>');

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>";

          ?>

Line 44 is the following line:-

Code:
$input = "$result['context']";

Any help would be appriciated.

Thanks alot

Jim
 
PHP does not like associative arrays within double quotes. That is a very very weird coding anyway, since you're enclosing a simple variable in double quotes, when that is not even needed. This should do exactly the same (without errors):
Code:
$input = $result['context'];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top