Recent Topics

1 Nov 06, 2006 22:35    

How can I configure a simple SQL-Statement so that it gives me back a list of all posts in a RANDOM order?

In the style of this:

$sql = "SELECT ID , post_title, post_urltitle ,
ROUND(COUNT(ID) / COUNT(DISTINCT postcat_cat_ID)) AS count
FROM evo_comments , evo_posts
INNER JOIN evo_postcats ON ID = postcat_post_ID
INNER JOIN evo_categories ON postcat_cat_ID = cat_ID
WHERE evo_posts.ID = evo_comments.comment_post_ID
AND (cat_blog_ID = ".$params['blog'].")
GROUP BY ID
ORDER BY `count` DESC
LIMIT ".$params['limit'];

5 Nov 09, 2006 01:02

But how can I change the statement to a sql-command that lists ALL entries? This seem to limit the output to entries with at least 1 comment...

6 Nov 09, 2006 01:09

what do you want the sql query to do/get?

7 Nov 09, 2006 01:17

All blog-articles of the current blog ID which are published.

8 Nov 09, 2006 01:35

$sql = 'SELECT post_ID, post_title, post_urltitle '.
'FROM evo_comments, evo_posts '.
'INNER JOIN evo_postcats ON post_ID = postcat_post_ID '.
'INNER JOIN evo_categories ON postcat_cat_ID = cat_ID '.
'WHERE cat_blog_ID = \''.$params['blog'].'\' '.
'GROUP BY post_ID '.
'ORDER BY RAND() '.
'LIMIT \''.$params['limit'].'\' ;';

Edit: re-added your params and stuff

9 Nov 09, 2006 10:11

Sorry to bother you again. I am glad that you want to help me but could it be that your SQL-Statement does not work because I use 0.91?

If I try it out, it gives me an error.

And I tried to format my sql-statement in the style of yours but it does not display anything:

$sql = "SELECT ID , post_title, post_urltitle 
FROM evo_posts
INNER JOIN evo_postcats ON ID = postcat_post_ID
INNER JOIN evo_categories ON postcat_cat_ID = cat_ID
WHERE (cat_blog_ID = ".$params['blog'].")
GROUP BY ID
LIMIT ".$params['limit'];

10 Nov 09, 2006 12:47

but could it be that your SQL-Statement does not work because I use 0.91?

You just hit the nail on the head.

With your previous one that worked but only returned ones that had comments, get rid of the order bys besides the rand() one as they are useless becaue of the rand() and also get rid of the evo_posts.ID = evo_comments.comment_post_ID part. should do the trick.

12 Nov 09, 2006 13:28

Should I upgrade because of security issues?

Ok I tried this:

$sql = "SELECT ID , post_title, post_urltitle
FROM evo_posts
INNER JOIN evo_postcats ON ID = postcat_post_ID
INNER JOIN evo_categories ON postcat_cat_ID = cat_ID
WHERE cat_blog_ID = ".$params['blog']."
GROUP BY ID
LIMIT ".$params['limit'];

But then the page stays blank ...

I am getting crazy.

Any idea?

13 Nov 09, 2006 13:40

Yeh, i think i would go with EdB on this one....

14 Nov 09, 2006 16:55

ok, but why does my code not work? it results in a blank page...


Form is loading...