Jump to content

Formatting Output


rocket_roche

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.