Hi Kim,

> I want to get the first 64 characters from a database row result and display
> only those 64 characters using PHP. The snipped code is here - I've deleted
> all the error trapping and comments:
>
> $result = @mysql_query("select ID, Writer, left(text,64) from Reports where
> writer like '%kim%';");
>
> while ($row = mysql_fetch_array($result)) {
> $ID=$row["ID"];
> $Writer=$row["Writer"];
> $text= $row["Text"];
>
> echo ("<p>" . $ID . " " . $Writer . " " . $Text . "</p>");
>
> This returns a blank result for Text. If I remove the left() from the SQL it
> works but displays the entire report - hundreds of words. How can I display
> only those first 64 characters - am I missing something obvious?


The 'fieldname' that is passed from MySQL to PHP depends upon the terminology of the 
SELECT clause (not the
schema of the table). So the column's name is text (BTW not a good choice) but the 
query knows the resultant
value as "left(text,64)"

- issue the query from the command line or in an admin pkg, and check the column 
headings, if you want to see
what I mean!

Use an AS to give the computed-column a 'good name' and you'll be away:-

$result = @mysql_query("select ID, Writer, left(text,64) as Intro from Reports where
 writer like '%kim%';");
...
> $text= $row["Intro"];

Regards,
=dn



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to