Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying truncated(?) data in table? 2

Status
Not open for further replies.

xWastedMindx

Technical User
Joined
Sep 3, 2002
Messages
67
Location
US
Is there a way to display truncated text using PHP? (or any other method) -- similar to the way a text link or string gets cut off if it's too long and can't fit in the given table or display area -- (ie. bla bla bla ....) specifically bringing attention to the " ... "


Thanks in advance.
Kenny



 
maybe the variable named $max is a reserved word? *shrug* try changing it to $maxStrLength
 
xWastedMindx
Once again, I copied and pasted your code and executed it on my box without any discernable trouble.
How's the rest of the page - line numbers for errors don't necessarily point to the offending line. It may be anywhere before that.

Bastien
Philosophical issues.
I believe that functions are abstract pieces of code that take an input and produce an output. The more abstract a function is, the more useful it seems. Write it once, use it anwhere you need it: for DVD names, video tape names, quotations....
To follow my own thinking here, the function could be even more abstract, having the max length as a passed in value, a more abstract name would also be better.
So, you have your points, it is a specific local function that probably will only be used in the very page.


 
Ok... well the only thing I can think of is that maybe my php.ini is screwy? Or maybe the table/database permissions?

Is there anything in the code/php.ini file that could cause trouble that I'm over looking?

Is there any kind of PHP syntax program I can use to run the code through? Maybe PHP comes with some sort of X Terminal (Konsole) script I can use?

miahmiah: I was also thinking the same thing. Maybe $max is a reserved function word. But the thing is, I've also changed the word to something else(before I even posted this problem), and it still didnt work.
So I have no idea what it could be.

DRJ478: The rest of my page is nothing more than HTML code. Which that wouldn't have any effect on PHP, would it? Well... that and at the very top I have my PHP connection/login/password stuff. But that's all correct because I've used it time and time again.. it's just this damn function giving me problems. EVERYTHING works perfect if I take out this function deal. At least no visual errors.
Maybe I should check my error logs.

I'm stumped.




 
So an unexpected T_VARIABLE happens when your code hits a variable, but isn't expecting it.

The most common cases of an unexpected T_VARIABLE in my own code is hands down the following snippit
Code:
1: $foo="bar"
2: $bar="foo";

Unexpected T_VAR Line 2

I.E. a missing semi-colon on a previous line.

In your code however, the problem lies here
Code:
while ($row = mysql_fetch_array($results))
{
Code:
    $dvdName = $row["dvdName"];
    $dvdPrice = $row["dvdPrice"];


  // Some sort of equation that makes it work
$row_color = ($row_count % 2) ? $color1 : $color2;

// Table output here

/**
 * showname
 * Returns formatted string with ellipsis if length exceeds
 * defined maximum
 * parameters:
 * myText -> string
 * returns:
 * formattedText -> string
**/
function showName($myText) {
   // set max characters
   $max = 22;

Your while loop is never closed, hence the parser is in panic mode when it hits the function line, I'm surprised it doesn't bonk there... but sometimes that's how parsers go.

As far as debugging this kind of thing, any text editor with proper code identing should have caught it for you... if your function defs don't hit the left mark, they're wrong.

-Rob
 
update:

I have no idea what I just did. But it works now.

The only thing I did was cut/paste the function code to a different section.. and then move it back to the bottom of the PHP code as previously suggested...and it now works.
Strange thing is.. I've done that time and time again and it didnt work before.

But now I'm happy! :-)
Thanks for your help everyone!



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top