Remy Porter’s CodeSOD item for The Daily WTF, dated 2026-10-06, revisits code written by DJ for his first paid web project. DJ was 19 at the time and had started taking odd web-development jobs at a low hourly rate. The function selected database content for a right-side banner. DJ had learned a lot since then, and the old function was still available for review.
<?php
$int = array();
$query = $sql->query("SELECT * FROM rightside");
while($row = $sql->objects('',$query)) {
$int[$row->id] = $row->id;
if ($row->id > $max) { $max = $row->id; }
}
$x = false;
while ($x == false) {
$rand = rand(0,$max);
foreach ($int as $thing) {
if ($thing == $rand) { $x = true; }
}
}
$query = $sql->query("SELECT * FROM rightside WHERE id = ".$rand);The routine runs `SELECT * FROM rightside` through `$sql->query` and iterates over the returned records with `$sql->objects('',$query)`. It uses each record’s `id` as both the key and value of a sparse array, records the largest ID in `$max`, and ignores the other columns returned by `SELECT *`. The routine then draws a number from `rand(0,$max)`, searches the array with `foreach`, and repeats until the number matches an existing ID. The final lookup is `SELECT * FROM rightside WHERE id = ".$rand`, assembled through string concatenation.
Porter calls the implementation poor even by early-00s PHP standards. He assigns part of the responsibility to the company that hired an inexperienced developer for very little money. The example also serves as a reminder that developers may recoil from code they wrote at 19. Porter sees no need for DJ to atone, and treats the episode as a lesson for programmers and employers.




Comments
No comments yet — be the first.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Nothing arrived? Check your spam folder — and mark the mail as "Not spam" so it lands in your inbox next time.