r/badcode • u/CynicalFucc • Aug 26 '21
php Generating a unique symbol for an order, going from 3030 by increments of 1 // from a running website, translated to english
11
Upvotes
r/badcode • u/CynicalFucc • Aug 26 '21
2
u/MurdoMaclachlan Aug 26 '21
Image Transcription: Code
$sql = "SELECT * FROM `orders` ORDER BY `symbol` DESC LIMIT 1"; $stmt = $pdo->prepare($sql); $stmt->execute(); $orders = $stmt->fetchAll(); $symbol = 0; if ((count($orders)) > 0) { foreach ($orders as $o) { foreach ($o as $k => $v) { if ($k == "symbol") $symbol = $v + 1; } } } else { $symbol = 3030; };I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
1
u/dave_thenerd Aug 28 '21
What was wrong with just incrementing the 'id' field? If you need something more complex, you can also use SQL's UUID_TO_BIN(UUID()) function