luke777 Posted April 1, 2009 Share Posted April 1, 2009 Hi there I'm new to php, still learning and I got stuck with this... I'd really appreciate any help, i've searched everywhere but without any success. What I am doing is grabbing some table data and for each putting it into html code to display a list of games from the database <? $sql = mysql_query('SELECT * FROM `games` WHERE `authorsite`="yippigames" ORDER BY RAND() LIMIT 0, 3') or mysql_error(); while($row=mysql_fetch_array($sql)) { $rowname = $row["name"]; $change = str_replace( " ", "-", $rowname); echo("<table class='gltable' cellpadding='0' cellspacing='0'><tr><td><a href='/game/".$row["id"]."/$change.html' rel='nofollow' class='gamelink'><img src='http://www.mysite.net/img/own/".$row["nameid"].".jpg' alt='".$row["name"]."' width='100' height='100' class='gamethumb' align='left' /></a><a href='/game/".$row["id"]."/$change.html' rel='nofollow' class='gamelink'>".$row["name"]."</a><br /><span class='gdesc'>".$row["desc"]."...</span></td></tr></table> \n");} ?> Everything is displaying great, but my only problem is I only want 20 characters of the description to display otherwise theres too much text on the page for each game. I just really need to make the ".$row["desc"]." in the code display just half of the full description. Any ideas ??? Any help is much appreciated! Thanks Luke. Link to comment https://forums.phpfreaks.com/topic/152072-changing-variable-length-only-want-15-characters-of-full-desc-into-variable/ Share on other sites More sharing options...
taquitosensei Posted April 1, 2009 Share Posted April 1, 2009 This should work $sql = mysql_query('SELECT *,substr(desc,20) as desc FROM `games` WHERE `authorsite`="yippigames" ORDER BY RAND() LIMIT 0, 3') or mysql_error(); Link to comment https://forums.phpfreaks.com/topic/152072-changing-variable-length-only-want-15-characters-of-full-desc-into-variable/#findComment-798609 Share on other sites More sharing options...
revraz Posted April 1, 2009 Share Posted April 1, 2009 substr http://www.w3schools.com/PHP/func_string_substr.asp Link to comment https://forums.phpfreaks.com/topic/152072-changing-variable-length-only-want-15-characters-of-full-desc-into-variable/#findComment-798610 Share on other sites More sharing options...
luke777 Posted April 1, 2009 Author Share Posted April 1, 2009 thanks guys, taquitosensei your code didnt work but i managed to play around with it a little and get it working another way You guys are great thank you very much Link to comment https://forums.phpfreaks.com/topic/152072-changing-variable-length-only-want-15-characters-of-full-desc-into-variable/#findComment-798702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.