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. Quote Link to comment 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(); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.