Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
$random :) <-- turned that frown upside down
Goto page 1, 2  Next
 
Reply to topic    Forum Index » Suggestions View previous topic
View next topic
$random :) <-- turned that frown upside down
Author Message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post $random :) <-- turned that frown upside down Reply with quote
I know I've probably mentioned it before.. I really miss $random in cnr 2.5.4 how hard is it to add? I remember doing some research on it before and trying some things then failing.. it's the only thing that has me going back to cn 1.3.6-1.4.1 once in a while. Does strawberry have a $random function?



Random + XFields = Fun

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm

Last edited by scottdallas on Mon Oct 16, 2006 12:21 am; edited 1 time in total
Sat Oct 07, 2006 11:52 pm View user's profile Send private message Visit poster's website AIM Address
Guest








Please login to hide the ads.

FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2736
Location: Germany

Post Reply with quote
Try this:



Open inc/show.news.php and find this:



Code:
foreach ($query as $bg => $row){




add above:

Code:
if(!function_exists('shuffle_it')){

function shuffle_it($array) {

   while (count($array) > 0) {

       $val = array_rand($array);

       $new_arr[$val] = $array[$val];

       unset($array[$val]);

   }

   return $new_arr;

}

}



if($random == TRUE){ $query = shuffle_it($query); }




Use $random = TRUE in your include code.
Tue Oct 10, 2006 10:47 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Well I tried it but no go. I guess I'll live without it and stop pestering you about it I just really loved that feature. Had so much potential.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Wed Oct 11, 2006 11:06 pm View user's profile Send private message Visit poster's website AIM Address
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2736
Location: Germany

Post Reply with quote
I just tested it myself, and it's working for me.
Wed Oct 11, 2006 11:17 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
oh well let me have another go at it... think i could have any server side issues like i seem to always have? i doubt it.. i must be doing something wrong.. i just tried on my advanced godaddy account, my regular godaddy account, and localhost and none of them want to do it. i dont think it's your fault though.. definitely something im doing wrong.



Code:
<?php

$number = "1";

$random = TRUE;

include("cutenews/show_news.php");

?>




Does that look right?



I've tried that and



Code:
<?php

$number = "1";

$random = "true";

include("cutenews/show_news.php");

?>


_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Thu Oct 12, 2006 3:14 am View user's profile Send private message Visit poster's website AIM Address
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2736
Location: Germany

Post Reply with quote
You're right. The above code only works when you display more than one news per page.



If you want to show a random single post find this in inc/show.news.php:

Code:
$query = $sql->select(array(

       'table'   => 'news',

       'orderby' => $sort,

       'join'      => array('table' => 'story', 'where' => 'id = post_id'),

       'where'   => $where,

       'limit'   => array(($skip ? $skip : 0), $number)

       ));




and add above:



Code:
if($random_single){

   $table_count = $sql->table_count('news');

   $skip = rand(0, $table_count-1);

   $random_single = false;

}




Add $random_single = true; to your include code.
Thu Oct 12, 2006 11:44 am View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy AWESOME!

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Thu Oct 12, 2006 9:36 pm View user's profile Send private message Visit poster's website AIM Address
GoldenGonaz



Joined: 04 Oct 2006
Posts: 28

Post Reply with quote
How do I show 4 random articles?



I tried both methods above none gave the right result.



With the first method, it only randomly displayed the 4 latest articles in a different order, instead of showing ANY 4 random articles in any order.



The second method, $random_single = true; doesn't work properly for 4 random articles either.



What would need to be added/changed to allow ANY 4 random articles from all categoeries from any date?
Wed Oct 18, 2006 5:07 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
You could fake it. Use the second example so you're using $random_single and instead of what you're probably doing:



Code:
<?php

$number = "4";

$template = "yourtemplate";

$category = "1";

$random = true;

include("cutenews/show_news.php");

?>




Do this.. I know it looks funny and is a pain.. but it'll show up on your page for your visitors correctly I promise.. even if it's rigged.



Code:
<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>

<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>

<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>

<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>




See what I mean?

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Wed Oct 18, 2006 6:08 pm View user's profile Send private message Visit poster's website AIM Address
GoldenGonaz



Joined: 04 Oct 2006
Posts: 28

Post Reply with quote
scottdallas wrote:
You could fake it. Use the second example so you're using $random_single and instead of what you're probably doing:



Code:
<?php

$number = "4";

$template = "yourtemplate";

$category = "1";

$random = true;

include("cutenews/show_news.php");

?>




Do this.. I know it looks funny and is a pain.. but it'll show up on your page for your visitors correctly I promise.. even if it's rigged.



Code:
<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>

<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>

<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>

<?php

$number = "1";

$template = "yourtemplate";

$category = "1";

$random_single = true;

include("cutenews/show_news.php");

?>




See what I mean?




Yeh, great idea! Thanks, I'll try and set it up now, my only worry is it might if a visitor is really unlucky show 2 of the same, 3 of the same or maybe even all 4!
Wed Oct 18, 2006 6:28 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
mm true but it's probably pretty unlikely. I hadn't thought of it like that. If your database is or gets large enough the odds will get slimmer Razz

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Thu Oct 19, 2006 2:21 pm View user's profile Send private message Visit poster's website AIM Address
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Can we zip the modified show.news.php file and put it in the additional downloads? I think people'd love to see it there. Just download and overwrite existing. I'll upload zip if you want unless this isn't worthy of that section. I really find it handy.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Wed Oct 25, 2006 1:38 am View user's profile Send private message Visit poster's website AIM Address
x-byte



Joined: 14 Nov 2005
Posts: 170

Post Reply with quote
Yea, this only randomize the first number of post (the number you choose) and not from the entire database. Would be great to have a fully functional one.
Sat Feb 03, 2007 7:39 pm View user's profile Send private message Visit poster's website
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
It randomizes my entire database Shocked

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Sun Feb 04, 2007 12:14 am View user's profile Send private message Visit poster's website AIM Address
twist



Joined: 05 Jan 2007
Posts: 28

Post Reply with quote
Yea it randomizes the entire database, but I think that is where the problem lies. It will random all news, but it will only display what you have assigned for your category. It's not randomizing within the category.



So it would appear if I had something like this setup:



Code:
<?PHP

   $static['template'] = 'Music;

   $static['number'] = 1;

   $static['category'] = 5;

   $random_single = true;

   ("cnr/show_news.php");

?>

<?PHP

   $static['template'] = 'Movies;

   $static['number'] = 1;

   $static['category'] = 7;

   $random_single = true;

   ("cnr/show_news.php");

?>




Using this script inside show.news.php



Code:
if($random_single){

   $table_count = $sql->table_count('news');

   $skip = rand(0, $table_count-1);

   $random_single = false;

}




It seems as if it calculates the total number of news items for both categories 5 and 7 and randomizes a single ID. So if the ID the $random_single identifies in the Music category is actually a movie, it will display nothing at all.



OR it is Randomizing the Categories themselves and will only display the random item if it falls on the same category that was identified in the embed code.
Mon Feb 05, 2007 8:09 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    Forum Index » Suggestions All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Music Lyrics.