List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:January 7 2001 11:29pm
Subject:Re: Another Newbish Question: Truncation
View as plain text  
At 11:51 AM -0800 1/7/01, Chadd Nervig wrote:
>I have a large string, and I want to display only the first X characters
>in it. How do I go about doing this? I've tried:
>
>echo LEFT($myrow["fulltext"],512);
>
>But that returns:
>
>Fatal error: Call to unsupported or undefined function left() in
><pageaddress> on line 112
>
>The MySQL specifically lists this as a supported function. What am I
>doing wrong, or what else could I do? If it perhaps is that I've got an
>old version of MySQL installed, I am unable to update at the moment, I'm
>only an end-user, so I need some way to do it as it is right now.

You're not using it in the proper context.

LEFT() is indeed a valid MySQL function, but you're calling it as a PHP
function, not a MySQL function.  You have to use LEFT() in the query that
you use to select your data.  For example:

$result = mysql_query ("SELECT LEFT(fulltext,512) FROM tbl_name");
if (!$result)
	die ("oops");
while ($myrow = mysql_fetch_array ($result)
{
	echo $myrow["fulltext"];
}

Alternatively, change your echo statement to call the PHP function
substr ($myrow["fulltext"], 0, 512).  See the PHP manual.

-- 
Paul DuBois, paul@stripped
Thread
Another Newbish Question: TruncationChadd Nervig7 Jan
  • Re: Another Newbish Question: TruncationStephen Johnson7 Jan
  • Re: Another Newbish Question: TruncationPaul DuBois8 Jan
RE: Another Newbish Question: TruncationQuentin Bennett7 Jan