All pastes #149414 Raw Edit

Mine

public text v1 · immutable
#149414 ·published 2006-08-25 19:38 UTC
rendered paste body
t0             b: <?

$query = "SELECT * FROM images";
$r=$db->getAll($query);

function randomize() {
    $rand = mt_rand(1, count($r));
    foreach($r as $key => $value)
        if($value[image_id] == $r)
            return($value[immage_path]);
}

function grabImage($img) {
    foreach($r as $key => $value)
        if($value[image_id] == $img || $value[image_name] == $img)
            return($value[image_path]);
}

if(isset($_SERVER['QUERY_STRING'])) {
    switch($_SERVER['QUERY_STRING']) {
        case 'random':
            $image = randomize();
            break;
        default:
            $image = grabImage($_SERVER['QUERY_STRING']);
    }
} else {
    $image = randomize();
}
?>
<html>
<head>
</head>
<body>
<img src="<?=$image?>">
</body>
</html>
t0             b: That's the full script complete
xACiD via LAPTOP: does that query a db? or i just drop it in my iamge directory
t0             b: you can make an onclick like thing to just have it point to itself
t0             b: That queries a DB using the DB PEAR module
t0             b: If you are using a mysql DB then you can just change it to use that
xACiD via LAPTOP: hmm you'll have to show me how to use that when i get hom elol
xACiD via LAPTOP: i'm at work now.. don'thave access to my web server
xACiD via LAPTOP: i'll email that to myself tho
t0             b: The only trouble is when it has to iterate through like 200,000 rows
t0             b: It's going to take a while to find the right one
t0             b: But that's just a really simple script right there
t0             b: You need a talbe with PK image_id; image_path; image_name  as the comlumns