...

View Full Version : EZ Problem, im stumped though



Al Capone
02-16-2006, 06:53 PM
hello and good morning :)
Ok, each game listed in my arcade displays a description, which i put in red on the code below, I want it so that only the first 20 charectors of the description is displayed then theres a "..." after it, i know this is probably an easy problem and i looked most everywhere but i couldnt find a solution.


<TR>
<TD>
<tr><td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="categHead">
<tr><td>&nbsp; Action / Adventure </td> </tr></table></td></tr><tr><td>

<TABLE cellSpacing=6 cellPadding=0 width="100%"
border=0>
<div align="center">
<table width="500" border="0">
<tr>
<td><div align="center">
<table width="500" border="0">
<tr>
<td width="494" height="0" valign="top">
<center>
<p><font size="1">
<?
$sql2 = "SELECT * FROM games WHERE category='Action / Adventure' ORDER BY played DESC LIMIT 0,3";
$result2 = mysql_query($sql2);
while($row2 = mysql_fetch_array($result2)) {
?>
<table width="400" border="0">
<tr><td>
<td width="50%" valign="top"><table width="494" border="0" cellpadding="0" cellspacing="3" class="game">
<td width="100"><img src="images/<? echo $row2["image"]; ?>" height="60" width="60"></td>
<td valign="top" width="234" class="normalText">
<div style='text-align:right; overflow:hidden; height:14px;'><a href="game.php?gameid=<? echo $row2["gameid"]; ?>"><FONT color=#000000><? echo $row2["category"]; ?> Games!</a></font></div>
<a href="game.php?gameid=<? echo $row2["gameid"]; ?>"><b><? echo $row2["name"]; ?></b></a><br>
<? echo $row2["desc"]; ?><br>
<a href="game.php?gameid=<? echo $row2["gameid"]; ?>"><b>Play now!</b></a></font></td></table>

</a>
<tr></td>

any help is greatly appriciated, thanks in advance

fci
02-16-2006, 07:05 PM
a thread where someone asked the same question:
http://www.codingforums.com/showthread.php?p=407749

raf
02-16-2006, 07:56 PM
and another one
http://www.codingforums.com/showthread.php?t=39199&highlight=word

Kid Charming
02-16-2006, 08:15 PM
Along with the solutions in the previously linked threads, you can also pull this directly from the database and bypass any extra php work:



SELECT
CONCAT(LEFT(desc,20),'...') AS desc
,etc.


If you'd rather have your breaks on words:



SELECT
CONCAT(SUBSTRING_INDEX(desc,' ',10),'...')
,etc.


That'll return everything to the left of the 10th space.

fci
02-16-2006, 08:35 PM
the problem with that is that 3 dots will always be appended (although you could do a case or an if probably to have it flop to what you want based on string length).

Al Capone
02-16-2006, 11:04 PM
Thanks for the replies ;)

I looked at both the links, and I didn't understand them

I'm sorry but I am fairly new to php, could someone tell me what to replace the line below with to make it show just the first 20 charectors


<? echo $row2["desc"]; ?>

thanks in advance

Al Capone
02-17-2006, 12:11 AM
thanks

fci
02-17-2006, 12:29 AM
hey sup, usually i dont double post but i am on a deadline and need to finish my site up, can someone please help me, thanks

but 3 solutions have already been posted to the thread, oh wait, you want us to do the work for you? you have a deadline? what have you been hired for? when do you think you will try understanding the code? this is absurd.

anyway


<?php

$min_length = 30;
if (strlen($row2['desc'])>$min_length)
echo substr($row2['desc'], 0, strrpos(substr($row2['desc'], 0, $min_len), ' ')).'...';
else
echo $row2["desc"];

?>

Al Capone
02-17-2006, 01:03 AM
Thanks bro, il try it

I have homework, thats the deadline :) i was just waiting by my computer, browser open, doing homework

thanks again bro :)

fci
02-17-2006, 01:05 AM
Thanks bro, il try it

I have homework, thats the deadline :) i was just waiting by my computer, browser open, doing homework

thanks again bro :)

:rolleyes:

Al Capone
02-17-2006, 01:08 AM
it didnt work, :( i only see ... thats it

any idea whats wrong?

fci
02-17-2006, 01:11 AM
I had a typo in my post, you are obligated to figure out what it is.

Al Capone
02-17-2006, 01:20 AM
Awww man, ok,

one of them was that the min should be max right? well i tried that didnt work

and the other was that you wrote 30 not 20 i made it 20, that didnt work either

so this is what i have now


<?php

$max_length = 20;
if (strlen($row2['desc'])>$max_length)
echo substr($row2['desc'], 0, strrpos(substr($row2['desc'], 0, $max_len), ' ')).'...';
else
echo $row2["desc"];

?>

fci
02-17-2006, 01:21 AM
keep trying

Al Capone
02-17-2006, 01:21 AM
Nevermind, you just spelled the length wrong,

Thank you so much :)

Now I will go finish my homework :(

thanks again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum