rocket_roche Posted January 23, 2009 Share Posted January 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142111-formatting-output/ Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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>"); Quote Link to comment https://forums.phpfreaks.com/topic/142111-formatting-output/#findComment-744272 Share on other sites More sharing options...
rocket_roche Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142111-formatting-output/#findComment-744472 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 That's a php issue, now, isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/142111-formatting-output/#findComment-747518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.