Solved How do I generate an short html list from a l

Microsoft / Vista
February 27, 2010 at 14:47:04
Specs: Windows Vista, 2GB
I am trying to make a site and in the sidebar of the site, I want there to be a column that says "More [whatever I decide on]" and then under that, I want it to list X amount of items, maybe ten or so depending on how it looks. But I want the X items to be chosen randomly and I want them to be hyper-linked to their page. So basically, I need a code where I can put in 100s of items, but it only displays 10 of those items at a time (each time it refreshes, a different set of ten). Kind of like how if you visit someones profile on facebook, it will show 6 of their 300 friends. And if it helps, the sidebar will just be an embeded external html or php or js. I don't know if some other languages don't work in my host service, but i know that javascript and php do, and I know jquery doesn't. So if you could make it javascript or php, that would be great. Thank you.

Here is an example list of what I want the external list to look like:

Also can you please give me an example code?

See More: How do I generate an short html list from a l

Report •

February 28, 2010 at 15:51:34
✔ Best Answer
I'm not sure what your specific need is, but you *might* try something like below or a variation to see if it will work for you.

I only did 9 items, but you could use as many as you needed and pull them using a database, file, or the array; to avoid repeating any items from a previous list, you'll need to track which 10 or whatever you showed previously... perhaps use the query string, a form, or cookie.

   $ran = array(-1, -1, -1);
   $index = 0;

   $items = array(0 => array("uri" => "some link", "desc" => "item 1"),
                  1 => array("uri" => "some link", "desc" => "item 2"),
                  2 => array("uri" => "some link", "desc" => "item 3"),
                  3 => array("uri" => "some link", "desc" => "item 4"),
                  4 => array("uri" => "some link", "desc" => "item 5"),
                  5 => array("uri" => "some link", "desc" => "item 6"),
                  6 => array("uri" => "some link", "desc" => "item 7"),
                  7 => array("uri" => "some link", "desc" => "item 8"),
                  8 => array("uri" => "some link", "desc" => "item 9")); 

   for(; $index < 3; ) {

      $rnd = rand(0, 8); 
      $flag = 0;         

      for($i=0; $i < 3; $i++) { 
         if($ran[$i] == $rnd) { 
            $flag = 1;

      if($flag == 0) {
         $ran[$index] = $rnd;

   echo "<p>More [whatever I decide on]</p>";

   for($i=0; $i < 3; $i++) {
      echo "<a href='" . $items[$ran[$i]]["uri"] . 
           "'>" . $items[$ran[$i]]["desc"] .

Something like that using php; you could do something similar using javascript, but client side scripting depends on the client having it enabled, which some users may not.


Report •
Related Solutions

Ask Question