I need to display part of text from mysql:
for exapmle i`m having 50characters and then i just want to display just part of it like 20characters
in the first page and the remain including the first as a link to another page.
That when someone clicks the link the whole 50 charecters wil appear.
Help me in doing this please.

Recommended Answers

All 8 Replies

Use substr to get the first 20 characters of the string:

$first=substr($content,0,20);
print $first;

In this example, $content is the original paragraph, 0 is the starting point of the content to be returned, and 20 is the number of characters to be returned.

<?php
include"config.php";

$result=@mysql_query('SELECT joketext,jokedate,name FROM comment');
$num_results=mysql_num_rows($result);
if( $num_results>0){


echo "<center><b><font color=blue size=3>There are <font color=red>$num_results</font> Comments</font></b></center>";
if(!$result){
exit('<p>Error perfoming query:' .
mysql_error() .'</p>');
}
//Diaplay the text of each joke in paragraph
while($row=mysql_fetch_array($result)){

$joketext=subtr($row,0,10);
$name=$row;
$date=$row;

echo"$joketext sent by:$name Date:$date";

?>
its is giving error:
Call to undefined function subtr() in C:\wamp\www\mimi.php on line 18

You missed the second s in substr: $joketext=subtr($row['joketext'],0,10); should be $joketext=substr($row['joketext'],0,10);

thankx alot it is working now))))

Use substr to get the first 20 characters of the string:

$first=substr($content,0,20);
print $first;

In this example, $content is the original paragraph, 0 is the starting point of the content to be returned, and 20 is the number of characters to be returned.

That's very handy to know, but I was wondering if you'd be able to tell me how you would instead of picking out characters, pick out actual words. For example:

"bah bah black sheep have you any wool, yes sir, yes sir, three bags full."

Instead of using substr (because each sentence will not have the same amount of characters) is there a function that will take full words, such as the first ten?

Thanks,

Anthony

u all done well

Hi,

I having the same problem with displaying text from msql.

ex: i have a file called language_pt.php,

inside i have a code <?=$aset[Lang_BRA]?> and at DB

<?
$HOME= "Home";
$LOGIN= "Entrar";
?>

Using that same code with the welcome.php(inside <?=$aset[Welcome]?>

it displays all text on the page, but with language appears blank.

I need help because i am not so good.

regards,

antwan1986, did you ever find an answer to your question?? I have the same problem and would really appreciate it if you could help me out. thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.