You have to know if you are making changes to sub-template overrride or to default generic.php file. When you go to /components/com_k2/templates/ you have generic.php there. This one is a default generic view, which means when you change something here, you will change the look of all the categories assigned to -default- sub template (you can select this option in category options in the backend).
However, if you work on an override /templates/NAME_OF_YOUR_THEME/html/com_k2/templates/generic.php this means you are actually overriding (replacing) the default generic.php file. When you make changes here, it will apply to all categories with "NAME_OF_YOUR_TEMPLATE" assigned as a sub-template. I hope you get the idea.
If you do, using firebug etc. locate the place in your category view where you want item author to appear, then edit generic.php file and paste the above code there.
For example I wanted it to be in <div class="sub-title"> so my code looks like this :
<div class="sub-title"> <!-- Item author --> <?php $config=new JConfig(); $query = " SELECT a.id as thisid, a.created_by as createdby, b.id as thisauthorid, b.name as thisauthor " ." FROM #__k2_items AS a " ." LEFT JOIN #__users AS b ON a.created_by=b.id " ." WHERE a.id=$item->id "; $db =& JFactory::getDBO(); $db->setQuery( $query ); $row = $db->loadObject(); $thisauthor = $row->thisauthor; $thisauthorid = $row->thisauthorid; ?> <span class="catItemAuthor"> <?php echo JText::_('By');?> <a href="<?php echo $config->live_site?>/index.php?option=com_k2&view=itemlist&task=user&id=<?php echo $thisauthorid;?>&Itemid=<?php echo $_REQUEST["Itemid"];?>"><?php echo $thisauthor; ?></a> </span>