Jump to content

Recommended Posts

I'm trying to output table contents on a webpage and my query is working fine. However, I would like to make sure that the first word in some columns is capitalized when output. 

 

$result = @mysql_query("SELECT b.title, b.image, b.price, a.fname, p.p_name
      FROM books b JOIN author a JOIN publisher p WHERE b.fk_a_id = a.a_id   and b.fk_p_id = p.p_id;" );

 

I'm outputting results to a table in HTML.

 

   echo("<tr><td> Title:   " . $row["title"] . "</td></tr>");
   echo("<tr><td> Author:   " . $row["fname"] . "</td></tr>");
   echo("<tr><td> Publisher:   " . $row["p_name"] . "</td></tr>");

 

What I would like to do is ensure that the title, fname and p_name are displayed with the first letter as a capital. Should this be done at the query level or is there  a HTML function to do this.

 

Any help greatly appreciated.

 

Regards,

 

Tony

Link to comment
https://forums.phpfreaks.com/topic/142111-formatting-output/
Share on other sites

while you could do it with a complicated MySQL statement, PHP has a function for it, so i would use that:

 

   echo("<tr><td> Title:   " . ucfirst($row["title"]) . "</td></tr>");
   echo("<tr><td> Author:   " . ucfirst($row["fname"]) . "</td></tr>");
   echo("<tr><td> Publisher:   " . ucfirst($row["p_name"]) . "</td></tr>");

Link to comment
https://forums.phpfreaks.com/topic/142111-formatting-output/#findComment-744272
Share on other sites

Thanks for that rhodesa - to take it a little further - if for example there were two words seperated by a space in the p_name field, is there a similar command that would capitalise the first letter of each seperate word?

 

Sorry - found that one - the ucwords() function.

 

Again, thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/142111-formatting-output/#findComment-744472
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.