Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorjustnajm
    • CommentTimeDec 30th 2006
     
    I have pictures with links to other sites on my page. After each reloading the script shows 5 random pics with links.

    I have 3 tables with 5 pics on each page so 15 pics is used at one time. There are 45 pics.

    Problem is that i have 2 or even 3 same pics after each reloading. what can i do to have no dublicate pics ?

    <?
    $ile = 5;
    $file = file("pics.txt");
    echo "<table width=\"600\"><tr>";
    for($i=0;$i<$ile;$i++)
    {
    srand((double)microtime()*1000000);
    $link = $file[array_rand($file)];
    $sp = explode("||", $link);
    if($sp[0]<>"")
    {
    echo "<td align=middle><a
    href=\"".$sp[2]."\"><img src=\"".$sp[0]."\" border=3></a><br><font
    style=\"font-weight: bold; font-size: 11px; font-family: Tahoma\">".$sp[1]."<br></font></td>";
    }
    }
    echo "</tr></table>";
    ?>

    Help me pls
    Najm.
    • CommentAuthorjiosis
    • CommentTimeJan 30th 2007
     
    Hi najm,
    Not sure what is the most optimized way but I think the best way is to define an array and store all the used numbers in it and each time you generate a new number check if it can be found in that array? if yes generate again and check again but if no continue and store it in array.

    Let me know if you want me to write the code for you.

    Thanks