PHP random string generator function

Jimmy Wales Reply 15:46
function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomStringValue = '';
    for ($i = 0; $i < $length; $i++) {
        $randomStringValue .= $characters[rand(0, strlen($characters) - 1)];    }
    return $randomStringValue ;}
Output the random string :-
// Echo the random string.
echo generateRandomString(); 

Displaying database records in unordered list format

Jimmy Wales Reply 09:52
Just keep a counter, increment it in the loop, and if it's an odd number set class to odd, if even set class to even. 
$result  = "";
$count = -1;

while ( $row = mysql_fetch_assoc( $query) ) {
  $class = $count++ % 2 === 0 ? "even" : "odd" ;
  $href  = $row["url"];
  $text  = $row["name"];
  $output .= "<li class='{$class}'><a href='foo?id={$href}'>{$name}</a></li>";
}

echo "<ul>{$result}</ul>";
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us