Re: limiting field extraction to 40 characters
| From: | mike karthauser | Date: | Thu, 12 Dec 2002 11:27:09 +0000 |
| Subject: | Re: limiting field extraction to 40 characters | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-24083@lists.php.net to get a copy of this message | ||
If i try the below in my query i get no results.
Ideally i would like to do this (not valid sql)
<? $result = mysql_query("SELECT * FROM courses",$db);
printf("<select name=\"coursecode\">\n");
while ($myrow = mysql_fetch_array($result)) {
$l=$myrow['coursecode'];
?><option value="<?=$l;?>"<?=($_POST['coursecode']==$l)?'
selected="selected"':"";?>><?=$myrow['left(title,40)'];?></option><?
}
printf("</select>\n");
?>
on 11/12/02 5:26 pm, Peter Beckman at beckman@purplecow.com wrote:
> LEFT(str,len)
> Returns the leftmost len characters from the string str:
>
> mysql> SELECT LEFT('foobarbar', 5);
> -> 'fooba'
>
> This function is multi-byte safe.
>
>
> select left(coursecode,40) from courses
> On Wed, 11 Dec 2002, mike karthauser wrote:
>
>> I am using
>>
>> <? $result = mysql_query("SELECT * FROM courses",$db);
>> printf("<select name=\"coursecode\">\n");
>> while ($myrow = mysql_fetch_array($result)) {
>>
>> $l=$myrow['coursecode'];
>> ?><option
>> value="<?=$l;?>"<?=($_POST['coursecode']==$l)?'
>>
>> selected="selected"':"";?>><?=$myrow['title'];?></option><?
>> }
>> printf("</select>\n");
>> ?>
>>
>> to generate a html <option><select>. Unfortunately a few of my course titles
>> are really long and this effects the rendering of the <option><select>
>> making it ultra wide.
>>
>> Is there a way i can print only the first 40 characters of the title - even
>> though the full title lives in the db still (it is used throughout the
>> site)?