Page 1 of 1

ucwords() problem

Posted: Tue Apr 23, 2002 6:06 pm
by qads
Sami | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

sorry to put all this code here but i want to show what i am trying to do.

Code: Select all

<?
$t = mysql_query($query);

$name = ucwords($name);

$count = mysql_num_rows($t);

while(list($name, $bmp, $source) = mysql_fetch_row($t))

echo("<table width='490' border='0' height='107' align='center' ' bgcolor='$tone_table_bg'>
  <tr>


    <td height='19' width='436' bgcolor='$tone_name_bg'>
      <p align='center'><b><font color='$tone_name'>$name - Bmp($bmp)</font></b>
    </td>
          </tr>
          <tr>

    <td height='76' width='436' valign='top' align='left' bgcolor='$source_bg'><font color=$source_font>$source</font></td>
          </tr>
        </table>");
}?>
this works fine, but i have some records in the database which are ALL CAP and some are MIxed :roll:

i want to use ucwords() to make all of seem like this: This That Or, so the firt letter of each word is a CAP.

so far this is not working.

any ideas on how or why it is not working?


thanks in adv.

Posted: Tue Apr 23, 2002 6:48 pm
by mydimension
its because you're applying the ucwords function before it has any content. try placing that line after the while statement and it should work.

Posted: Wed Apr 24, 2002 4:09 am
by qads
i did that before, but it only shows 1 record.

Posted: Wed Apr 24, 2002 5:49 am
by twigletmac
You probably want to switch things around so you get

Code: Select all

<?php
$t = mysql_query($query); 

$count = mysql_num_rows($t); 

while(list($name, $bmp, $source) = mysql_fetch_row($t))
{
    $name = ucwords(strtolower($name)); 

    echo <<<END
<table width="490" border="0" height="107" align="center" bgcolor="$tone_table_bg"> 
<tr> 
<td height="19" width="436" bgcolor="$tone_name_bg"> 
<p align="center"><b><font color="$tone_name">$name - Bmp($bmp)</font></b> 
</td> 
</tr> 
<tr> 
<td height="76" width="436" valign="top" align="left" bgcolor="$source_bg"><font color=$source_font>$source</font></td> 
</tr> 
</table>
END;
}

?>
The strlower() function will convert the string to lower case so that all-caps and mixed case is not an issue and then ucwords() should work better.

You need an opening brace after your while loop ({).

The echo <<<END ... END; statement means that your HTML formatting will be preserved and you don't have to worry about escaping quotes or other special characters. IIRC single quotes are not valid in HTML.

Hope this helps,
Mac

Posted: Wed Apr 24, 2002 10:06 am
by qads
thanks alot, that helped.