Latest commented on

Discuss PivotX 2.0.x here. Non-PivotX related discussions go in The Drain.

Re: Latest commented on

Postby Marza » Tue Jan 26, 2010 10:16 pm

No, doesn't return anything. I tried "echo $rows;" as well, which returned 'entry_uid'.
Marza
 
Posts: 85
Joined: Sat Dec 12, 2009 8:49 pm

Re: Latest commented on

Postby Harm10 » Wed Jan 27, 2010 1:19 pm

Then either the SELECT is still wrong or it doesn't give you any rows as a result.
As I can't check the SELECT you could try PHPMYADMIN on your webhostingpage to check whether the table name is existing and what the result is for this query. Otherwise you need to have Bob to take another look at his supplied code.
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
Harm10
Developer
 
Posts: 1844
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: Latest commented on

Postby Marza » Wed Jan 27, 2010 11:03 pm

I think I've made some progress, by replacing:
Code: Select all
$sql->query("SELECT 'entry_uid' FROM pivotx_comments GROUP BY 'entry_uid' ORDER BY 'date' DESC LIMIT 20;");

with:

Code: Select all
 $sql->query("SELECT entry_uid FROM pivotx_comments GROUP BY entry_uid ORDER BY 'date DESC LIMIT 20;");

(the difference is in the quotes)

Now "echo $rows;" does no longer return 'entry_uid', but a list of entry_uids. However, "echo $latest_uids;" still turns up nothing (both were placed after the smarty assign phrase). So I guess there must be something wrong in the following part?

Code: Select all
// Assign them in smarty
$this->assign('latest_uids', $rows);
Marza
 
Posts: 85
Joined: Sat Dec 12, 2009 8:49 pm

Re: Latest commented on

Postby Harm10 » Wed Jan 27, 2010 11:17 pm

Peculiar that leaving out the quotes gives you a result in $rows.
Maybe if you do the same for latest_uids in the assign it will also work?
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
Harm10
Developer
 
Posts: 1844
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: Latest commented on

Postby Marza » Wed Jan 27, 2010 11:26 pm

No, tried that, no change.
Marza
 
Posts: 85
Joined: Sat Dec 12, 2009 8:49 pm

Re: Latest commented on

Postby Bob » Thu Jan 28, 2010 2:31 pm

oh, don't use quotes for variables:

Code: Select all
[[ subweblog .. uid=$latest_uids ]] ... [[/subweblog ]]


Smarty is a bit fickle that way. :-)
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Latest commented on

Postby Marza » Thu Jan 28, 2010 4:24 pm

Bob, I removed those quotes as well, but since $latest_uids still seems empty, it won't work. See my comment above, about how "echo $rows;" does return the uids and "echo $latest_uids;" doesn't.
Marza
 
Posts: 85
Joined: Sat Dec 12, 2009 8:49 pm

Re: Latest commented on

Postby Harm10 » Thu Jan 28, 2010 6:50 pm

This is all very strange..... it looks like smarty is not working properly!
What happens if you code
Code: Select all
$this->assign('test_var', 'Marza was here');
echo $test_var;
or should it maybe read
Code: Select all
$this->assign('latest_uids', array($rows));
Or maybe smarty isn't active?
Code: Select all
// create object
$testthis = new Smarty;
$testthis->assign('latest_uids', $rows);
echo $latest_uids;
Quality is in the detail of things............

Want to change or update your PivotX site? Mail or PM me!
Harm10
Developer
 
Posts: 1844
Joined: Wed Jun 17, 2009 9:37 am
Location: Somewhere in The Netherlands (aka Holland)

Re: Latest commented on

Postby hansfn » Thu Jan 28, 2010 8:57 pm

@Harm: You are off-track here. You are testing Smarty completely wrong.

@Marza:I'm 110% sure you just have made a typo when copying the code Bob posted. Post the complete code you are using. (PS! In stead of the "complex" subweblog statement, just use [[ $latest_uids ]] to test the value.)
hansfn
Developer
 
Posts: 3191
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Latest commented on

Postby Marza » Fri Jan 29, 2010 7:20 am

Hans, you're spot on. After all the changes, I went back to the original code, to see if we missed something. And we did. All be it, not in the php part, but in the 'template part', namely the [[ literal ]] [[ /literal ]], that is supposed to be included in all subweblog codes.

This is what I'm using right now (almost the same as Bobs code, is:
Code: Select all
[[php]]

global $PIVOTX;

$sql = new sql('mysql',
            $PIVOTX['config']->get('db_databasename'),
            $PIVOTX['config']->get('db_hostname'),
            $PIVOTX['config']->get('db_username'),
            $PIVOTX['config']->get('db_password')
        );

$sql->query("SELECT entry_uid FROM pivotx_comments GROUP BY entry_uid ORDER BY `date` DESC LIMIT 20;");

// Get the results.
$rows = $sql->fetch_all_rows();

// make them manageable..
$rows = implode(', ', make_valuepairs($rows, '', 'entry_uid'));

// Assign them in smarty
$this->assign('latest_uids', $rows);

[[/php]]
 [[ $latest_uids ]]


It turns out, $latest_ids is not empty at all ( although "echo $latest_uids;" within the php-code still returns nothing!). So we've been a) to occupied with finding flaws in the php code, to notice the missing [[ literal ]] and b) been testing an echo statement that apparently doesn't reflect the outcome we expected.
Replacing [[ $latest_uids ]] by the earlier more complex subweblog statement works as well now (profided the 'literal'-code is added)

So, we've made great progress, only the outcome isn't quite right yet. When I compare the outcome of [[ $latest_uids ]] with "The latest comments" that are shown on the dashboard, they don't match. I've got a feeling that the "GROUP BY entry_uid" is processed before the "ORDER BY `date` DESC" statement and that it should be the other way round, but haven't found out how to achieve that.
Code: Select all
$sql->query("SELECT entry_uid FROM pivotx_comments ORDER BY `date` DESC LIMIT 20;");

selects the entries in the right order, only with doubles (it's 'latest comments', instead of 'commented on'). It's the 'GROUP BY entry_uid' which returns a completely different order. I haven't quite figured out what the logic behind that ordering is , but know it should be different.

I think what should happen is this:
- all comments must be ordered by date first
Code: Select all
$sql->query("SELECT entry_uid FROM pivotx_comments ORDER BY `date` DESC;");

- then form all (duplicate) entry_uids only those with the newest date (as we're in pivotx_comments, this is actually the comment date) should be kept.
Marza
 
Posts: 85
Joined: Sat Dec 12, 2009 8:49 pm

PreviousNext

Return to 2.x Discussion

Who is online

Users browsing this forum: No registered users and 0 guests