View Full Version : Display all comments in 1 place
stevler
11-01-2009, 12:53 PM
I'm modding the templates and my limited php experience is letting me down. I'm trying to call all the comments for a raid into one place and display. So far I have been trying to place this code into view.php
The bellow code only displays the first comment at the top of the screen.
$sql['SELECT'] = '*';
$sql['FROM'] = 'signups';
$sql['WHERE'] = 'raid_id='.$id;
$db_raid->set_query('select', $sql, __FILE__, __LINE__);
while($datc = $db_raid->fetch()) {
if (!($datc['comments']==NULL)) {
$sql['SELECT'] = '*';
$sql['FROM'] = 'character';
$sql['WHERE'] = '';
$db_raid->set_query('select', $sql, __FILE__, __LINE__);
while($datd = $db_raid->fetch()) {
if ($datc['character_id']==$datd['character_id']) {
echo $datd['char_name'].'<br />';
echo $datc['comments'].'<br />';
} }}}
This code would be terrible at the best of times, I know, dont tell me.
I have also a vague idea on how the template content is called, enough to know this would not work.
Anyway can anyone help.
Example page if your interested http://asylum.9-feet.com/raider/index.php?option=com_view&id=99
Edit - I seem to have to post twice?
orion808
11-01-2009, 06:58 PM
When you say "all the comments", do you mean all the comments of each character of that riad or the raid's comments?
This might help/work, unsure.
$unset($sql);
$sql['SELECT'] = 's.comments, c.char_name';
$sql['FROM'] = 'signups s';
$sql['JOIN'] = array('TYPE'=>'LEFT','TABLE'=>'character c','CONDITION'=>'c.character_id=s.character_id');
$sql['WHERE'] = 'raid_id='.$id;
$db_raid->set_query('select', $sql, __FILE__, __LINE__);
while($data = $db_raid->fetch()) {
if ($data['comments'] != NULL) {
echo $data['char_name'].'<br />'.$data['comments'].'<br />';
}
}
The above code joins the tables together so you don't need 2 queries. It also simplifies your output.
Also, "($datc['comments'] != NULL)" is a better way to write "(!($datc['comments']==NULL))".
orion808
11-01-2009, 07:15 PM
And yes, you did double post but the spam filter caught it.
stevler
11-02-2009, 09:44 AM
Thanks, any helpfull corrections with my php are welcome. And yes I am trying to display every comment from every character in the raid.
Now the thing is, I have the bellow code but I can not seem to place the output where I want it. I am trying to place the output into the side bar but it seems to appear at the top of the page.
Placed in view.php
//Set up comments array
$comts = array();
//Pull comments and character names from MySQL
unset($sql);
$sql['SELECT'] = 's.comments, c.char_name';
$sql['FROM'] = 'signups s';
$sql['JOIN'] = array('TYPE'=>'LEFT','TABLE'=>'character c','CONDITION'=>'c.character_id=s.character_id');
$sql['WHERE'] = 'raid_id='.$id;
$db_raid->set_query('select', $sql, __FILE__, __ );
//and build comments array
while($data = $db_raid->fetch()) {
if ($data['comments'] != NULL) {
array_push($comts,
array(
'name' => "{$data['char_name']}<br />",
'comment' => "{$data['comments']}<br />",
)
);
}
}
//Define function to display comments
function showComments($comts){
$keycount = 0;
while (list ($key,$value) = each($comts[0])){
$keycount++;
}
$rowcount = sizeof ($comts);
for($rowCounter = 0;$rowCounter < $rowcount;$rowCounter++){
$valuesarray = array_values($comts[$rowCounter]);
for($colCounter = 0; $colCounter < $keycount; $colCounter++){
//Display here
echo $valuesarray[$colCounter];
}
}
}
Also in view.php
............ups', $queue);
$p->assign('allcomms', showComments($comts));
$p->display(RAIDER_TEMPLATE_PATH.'view.tpl');
} else { ........
And in view.tpl
<div id="sidebar">
<div style="">{$allcomms}</div>
</div>
Can anyone help with direction on how I can place my code in the templates?
orion808
11-02-2009, 10:09 AM
//Display here
echo $valuesarray[$colCounter];
This does exactly that...it displays "here", which is before the template is called, but after the header is created.
At the bottom of your function, try return instead of echo. You need to store your values to an array and then return that result.
stevler
11-03-2009, 07:43 AM
So, your saying I need to have a function build an array and return that array. Then send that array to the page template to be built. If so where in the phpraider code do I need to call the array?
orion808
11-03-2009, 10:02 AM
call function
function returns the array
array is assigned to the template
template structures/uses the array (foreach loop)
With your situation, you are wanting a certain number of columns. I'm not exactly sure how to do that as it would require the every X piece of data would be grouped together and placed in it's own table/column/row.
stevler
11-03-2009, 11:02 AM
I got it working with a shotgun approach. Very scruffy but it works.
In view.php
//Set up comments array
$comts = array();
//Pull comments and character names from MySQL
unset($sql);
$sql['SELECT'] = 's.comments, c.char_name';
$sql['FROM'] = 'signups s';
$sql['JOIN'] = array('TYPE'=>'LEFT','TABLE'=>'character c','CONDITION'=>'c.character_id=s.character_id');
$sql['WHERE'] = 'raid_id='.$id;
$db_raid->set_query('select', $sql, __FILE__, __ );
//and build comments array
while($data = $db_raid->fetch()) {
if ($data['comments'] != NULL) {
array_push($comts,
array(
'name' => "{$data['char_name']}<br />",
'comment' => "{$data['comments']}<br />",
)
);
}
}
//Cycle through array and setup every individual
//comment into template. Not very pretty but it
//works:D
for($i=0; $i< count($comts); $i++) {
$str = join($comts[$i]);
$p->assign('allcomms'.$i, $str);
}
And in view.tpl
<div style="">{$allcomms1}{$allcomms2}{$allcomms3}{$allcomms4}{$ allcomms5}{$allcomms6}{$allcomms7}{$allcomms8}{$al lcomms9}{$allcomms10}{$allcomms11}{$allcomms12}{$a llcomms13}{$allcomms14}{$allcomms15}{$allcomms16}{ $allcomms17}{$allcomms18}{$allcomms19}{$allcomms20 }{$allcomms21}{$allcomms22}{$allcomms23}{$allcomms 24}</div>
If I have more than 24 people leave a comment then I'm in trouble. I'd be be pleased though as I didnt think I had that many friends.
Orion, thanks for your input. When I finalise my phpraider template I'll have to post it here.
Yasharah
03-03-2010, 03:08 AM
it doesn't work
|
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.