MySQL Forums
Forum List  »  PHP

Output formatting help
Posted by: Michael DK
Date: April 25, 2016 08:42AM

Being not familiar with sql at all hope somebody could help me.
I just need to change/format the output from this sql query in my php template for a forum.
When the query runs the output is sent to the variable "message" and written directly in the forum thread.
However the out put looks bad as it is not formatted and just a list with "+ and _ " in the output.
I would like to see it formatted as a table or at least a list where the first field has 20 characters before the 2nd field is displayed.
This is the code I have and the bad formatted output I want to change is:
'[URL=\'' . $webRoot . 'members/' . $v['user_id'] . '/\'' . ']' . $v['username'] . '[/URL]' . ' - ' . $v['rsvp_count'] . ' + ' . '[I]' . $v['note'] . '[/I]';

-----------------------------------------------------------------------------

// run query
$results = $db->fetchAll("
SELECT xf_rsvp.username,
xf_rsvp.rsvp_count,
xf_rsvp.note,
xf_user.user_id
FROM xf_rsvp
INNER JOIN xf_user ON xf_user.username = xf_rsvp.username
WHERE xf_rsvp.thread_id = ?
ORDER BY xf_rsvp.username ASC
", $threadId);

// define variables
$rsvpMessage = '';
$rsvpCount = 0;

// get link to forum index
$webRoot = XenForo_Link::buildPublicLink('full:index');

// create rsvp list
foreach ($results as $k => $v)
{
// define variable
$rsvpList = '';

if ($useFriendlyUrls)
{
if ($v['note'])
{
$rsvpList = $rsvpList . '[URL=\'' . $webRoot . 'members/' . $v['user_id'] . '/\'' . ']' . $v['username'] . '[/URL]' . ' - ' . $v['rsvp_count'] . ' + ' . '[I]' . $v['note'] . '[/I]';
}
else
{
$rsvpList = $rsvpList . '[URL=\'' . $webRoot . 'members/' . $v['user_id'] . '/\'' . ']' . $v['username'] . '[/URL]' . ' + ' . $v['rsvp_count'];
}
}

if (!$useFriendlyUrls)
{
if ($v['note'])
{
$rsvpList = $rsvpList . '[URL=\'' . $webRoot . '?members/' . $v['user_id'] . '/\'' . ']' . $v['username'] . '[/URL]' . ' - ' . $v['rsvp_count'] . ' + ' . '[I]' . $v['note'] . '[/I]';
}
else
{
$rsvpList = $rsvpList . '[URL=\'' . $webRoot . '?members/' . $v['user_id'] . '/\'' . ']' . $v['username'] . '[/URL]' . ' + ' . $v['rsvp_count'];
}
}

// get rsvpCount
$rsvpCount = $rsvpCount + $v['rsvp_count'];

// create new message
$rsvpMessage = $rsvpMessage . '
' . $rsvpList;

}

if ($rsvpCount != 0)
{
// define rsvpMessage
$rsvpMessage = $rsvpMessage . '
' . '
' . new XenForo_Phrase('rsvp_total') . $rsvpCount;

Options: ReplyQuote


Subject
Written By
Posted
Output formatting help
April 25, 2016 08:42AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.