I’ve wrote a function which outputs the array data from the database and in turn finds out the values from a column in the table for the user which groups they belong to which is stored such as:
1,2,3
The above represents the id for the groups in the group table and I use explode to check these in the final two functions and return the group names seperated by commas as a string value. The issue I have is firstly I want to trim the last comma from the string which I can’t seem to do with ‘substr_replace’
Secondly I want the string to be returned so I can show it in the main output in HTML but it doesn’t seem to display either.
Any of the issues you can help with would be great.
Thanks
public function getTwitterIndexList() {
$dbo = new Database();
if ($result = $dbo->_query("SELECT * FROM `journalist` ORDER BY `journalist_cdr_rating` DESC")) {
if ($rows = $dbo->getObjectList($result)) {
$i = 1;
foreach ($rows as $journo) {
$output = '<tr>';
$output.='<td class="rank">'.$i.'</td>';
$output.='<td class="info">';
$output.='<img src="./images/icon_sample.gif" alt="'.$journo->journalist_name.'" />';
$output.='<h2>'.$journo->journalist_name.'</h2>';
$output.='<p><a href="http://www.twitter.com/'.$journo->journalist_username.'" target="_blank" class="twitterlink">@'.$journo->journalist_username.'</a><br /><span class="type">Publication<br />Groups: ';
$output.= $this->getGroups($journo->journalist_groups);
$output.='</span><br /><a href="#" target="_blank" class="weblink">'.$journo->journalist_web_address.'</a></p>';
$output.='</td>';
$output.='<td class="rated">'.$journo->journalist_klout_score.'</td>';
$output.='<td class="rated">'.$journo->journalist_peer_score.'</td>';
$output.='<td class="rated cdr">'.$journo->journalist_cdr_rating.'</td>';
$output.='<td class="rated r_button"><a href="/?screename='.$journo->journalist_username.'"><span class="hidden">View More</span></a></td>';
$output.='</tr>';
echo $output;
$i++;
//print_r($rows);
}
}
}
return false;
}
public function getGroups($groups) {
$list = explode(",",substr($groups,0));
foreach ($list as $item) {
$output = $this->getGroupNameById($item);
$grouplist = substr_replace($output,"",-1);
echo $grouplist;
}
}
public function getGroupNameById($id) {
$dbo = new Database();
$output = '';
if ($result = $dbo->_query("SELECT `group_name` FROM `groups` WHERE `group_id`=".intval($id)." LIMIT 1")) {
if ($row = $dbo->getObject($result)) {
$output.= $row->group_name.', ';
return $output;
}
}
return false;
}