Feed aggregator
Harvard Astronomy Professor Thinks He Has New Evidence of Alien Spacecraft
Read more of this story at Slashdot.
Russian Cosmonaut Sets Record For Most Time In Space
Read more of this story at Slashdot.
CodeSOD: Return Country
Let's say you have a database table containing a list of countries. Given the primary key of a country in that table- an arbitrary ID field- you need to look up the name of that country.
Curtis's predecessor dropped this solution:
function return_country($id) { $sql = "SELECT * FROM countries"; $qry = db_query($sql); if(mysql_num_rows($qry)>0){ while($row = mysql_fetch_assoc($qry)){ $a[$row['id']] = $row['name']; } }else{ return array(); } return $a[$id]; }I guess they got the memo about not doing SQL injection flaws, but missed the "because you use query parameters". Instead, this queries the entire list of countries, iterates across them to build a mapping of ID to country name, and then uses that map to return the correct result.
This code really "shines" in its details. Sure, we could solve this with a query, but even if we opt to iterate across the table, we could just return from inside the loop. But no, we build an associative array.
And while it'd be better to return an error when the ID can't be found, we could return an empty string, but no- we return an empty array.
Return country? I'd rather return this code.
[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.A Famous Climate Scientist Is In Court With Big Stakes For Attacks On Science
Read more of this story at Slashdot.
Bluesky Opens To the Public
Read more of this story at Slashdot.
Report Reveals Decline In Quality of USB Sticks, MicroSD Cards
Read more of this story at Slashdot.
Boston Dynamics' Atlas Tries Out Inventory Work, Gets Better At Lifting
Read more of this story at Slashdot.
3 Million Malware-Infected Smart Toothbrushes Used In Swiss DDoS Attacks
Read more of this story at Slashdot.
Meta Will Start Labeling AI-Generated Images On Facebook, Instagram and Threads
Read more of this story at Slashdot.
Crypto Mining Company Loses Bid To Force Canadian Utility Company To Provide Power
Read more of this story at Slashdot.
Warner, Fox, Disney To Launch Streaming Sports Joint Venture
Read more of this story at Slashdot.
UK, France Pitch Rules To Curb Spyware Abuse
Read more of this story at Slashdot.
The EU Proposes Slashing Pollution 90 Percent by 2040
Read more of this story at Slashdot.
YouTube Has Become One of the Biggest Pay TV Services in the US
Read more of this story at Slashdot.
Space-based Research May Lead To Cancer 'Kill Switch'
Read more of this story at Slashdot.
Microsoft Revives Aggressive Windows 11 Upgrade Campaign With Intrusive Popups
Read more of this story at Slashdot.
US To Restrict Visas For Those Who Misuse Commercial Spyware
Read more of this story at Slashdot.
Google and Mozilla Don't Like Apple's New iOS Browser Rules
Read more of this story at Slashdot.
Did You Use ChatGPT On Your School Applications? These Words May Tip Off Admissions
Read more of this story at Slashdot.
DocuSign To Lay Off 6% of Workforce, or About 440 Jobs
Read more of this story at Slashdot.