/    Sign up×
Community /Pin to ProfileBookmark

substr() with the database value

hi..i am new to php.. can anyone help me.. i have problem with substr(). the thing is i want to limit the number of character to 300.. so i used substr function. but as for the syntax i need to use a string type for substring, but my intention is i need to take the value from the database and in that i need to limit the cahrcter to 300.. as it will return array i dnt knw how to proceed..
and if i use substr($des,0,300) its working fine for first 3 data base value, but not workng for rest of them.. here is my code..pls anyone help me..

<?php
include(“connection.php”);
$q=”select * from descript d,menureg m where m.menuid=d.deslink”;
$r=mysql_query($q);
$row=mysql_fetch_array($r);
while($row!=NULL)
{
$id=$row[‘descid’];
$menu=$row[‘menuname’];
$name=$row[‘title’];
$desc1=$row[‘desclink’];

$desc=$row[‘descrdata’];

$des3=strlen($desc);

$desc2=substr($desc,0,300);

?>

<td><?php echo $desc2;?></td>
<?php
$row=mysql_fetch_array($r);

}
?>

</table> </td>

i dnt knw how to proceed.. even i tried with conversio ie.by using implode() .. but its not working.. can anyone help me.. my website url is [url]www.kanoesoftwares.com[/url]..

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NihilisteOct 03.2009 — The first thing I would suggest is to make your code clearer and use mysql_fetch_assoc() instead of mysql_fetch_array(), like this:

[code=php]

<?php
include("connection.php");

$q = "select * from descript d,menureg m where m.menuid=d.deslink";
$r = mysql_query( $q );

while( $row = mysql_fetch_assoc($r) ) {

$id = $row['descid'];
$menu = $row['menuname'];
$name = $row['title'];
$desc1 = $row['desclink'];

$desc2 = substr( $row['descrdata'], 0, 300 );
$desc3 = strlen( $row['descrdata'] );

echo "<td>" . $desc2 . "</td>";
}
?>

[/code]


Next the only thing I can see for the substr() not returning a value after the third row, is that you have nothing in $row[ 'descrdata' ] after the third one.

Hope this will help!

MGB
Copy linkTweet thisAlerts:
@prathikanoeauthorOct 05.2009 — hi..thanks for your reply.. but i have value after the 3rd row but its not fetching that..the thing is i am using an javascript editor to change the fonts and all..if i remove that editor its working fine.. is there any wrong with the js editor, but i want to use the editor.. so how can i solve this. the substr() is working fine but its not displaying the whole data... canyou help me please..


thanks in advance

prathi
×

Success!

Help @prathikanoe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...