2 marcdk Nov 08, 2006 08:28

change ORDER BY `count` DESC to ORDER BY RAND()
http://www.google.com.au/search?hl=en&q=mysql+random+order&btnG=Google+Search&meta=
http://lists.evolt.org/archive/Week-of-Mon-20021230/131053.html
Thanx!
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...
what do you want the sql query to do/get?
All blog-articles of the current blog ID which are published.
$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
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'];
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.
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?
Yeh, i think i would go with EdB on this one....
ok, but why does my code not work? it results in a blank page...
i don't know, thats why i'm saying upgrading ;)
nobody knows?