hyster Posted January 8, 2011 Share Posted January 8, 2011 i want to be able to use ucwords in my whole return results. i know this works. $choice1 = ucwords($rows['auth']); BUT. my query returns 14 $rows of data so i thought of doing this instead of doing a new chunk of code for each row. $sql = "SELECT * from dsgi_serval $column "; $result1=mysql_query($sql); $result = ucwords($'result1'); while($rows=mysql_fetch_array($result)){ echo "$rows"; } needless to say that does not work. i have tried to google this but i only get matches for manual arrays and not an sql query. is there a way of doing this? Thanks Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/ Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Because $result holds a result resource, not an array. You also won't be able to echo $rows; all you'll get back from that should be 'Array'. I haven't tested this, but it *should* work to capitalize each one. You'll need to replace the echo pre/print_r()/echo pre with appropriate echo statements to format the output how you'd like it. $sql = "SELECT * from dsgi_serval $column"; $result=mysql_query($sql); while( $rows=mysql_fetch_array($result) ) { array_map('uc_words', $rows); echo '<pre>'; print_r($rows); echo '</pre>'; } Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/#findComment-1156677 Share on other sites More sharing options...
hyster Posted January 8, 2011 Author Share Posted January 8, 2011 sort of works lol it still loops but i get this error for every loop. Warning: array_map() expects parameter 1 to be a valid callback, function 'uc_words' not found or invalid function name in file.php Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/#findComment-1156688 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 Try removing the underscore I manages to accidentally put in ucwords . . . Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/#findComment-1156695 Share on other sites More sharing options...
hyster Posted January 8, 2011 Author Share Posted January 8, 2011 the errors have gone and loops fine but uwords or strtoupper dont affect the vars Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/#findComment-1156708 Share on other sites More sharing options...
Pikachu2000 Posted January 8, 2011 Share Posted January 8, 2011 I can't seem to get much right today for some reason. Add: $rows = right before the array_map function. If the result of the function isn't assigned to the var, it's pretty pointless . . . Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/#findComment-1156709 Share on other sites More sharing options...
hyster Posted January 8, 2011 Author Share Posted January 8, 2011 its wierd but strtoupper and strtolower work fine but ucwords does not. im happy enough with strtoupper working. BIG thanks pikachu Link to comment https://forums.phpfreaks.com/topic/223779-ucwords/#findComment-1156713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.