The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

6

It would be better to use GROUP by in your SQL. By this way you will get rid of long SQL query. SELECT Rating, COUNT(id) FROM list WHERE songID=:songID GROUP BY Rating;


4

You are missing charset in your DSN and you have emulated prepared statements still on. This could potentially leave your vulnerable to SQL injection. See Are PDO prepared statements sufficient to prevent SQL injection? As I have pointed out to you in an answer on Stack Overflow you should set the proper charset and disable emulated prepared statements. $...


3

w3schools gets its placement from shelling out big bucks for high ranking in search engine results (as I've read), not for being the best resource for web development advice. When in doubt, read Stack Exchanges sites. SE sites enjoy the benefit of constant peer review. If something is not quite right, eventually a whistleblower is going to find it and ...


3

w3fools following a W3 tutorial I would say the most important suggestion you can get is never ever use any tutorial from w3shcools. They are dubbed as "w3fools" for a reason. Their tutorials are outdated, buggy and - as you can already see from other answers - far from being optimal making you a monkey writing a lot of useless code that repeats again ...


2

I don't really like the kind of a review that is popular on this site which only states that your code has some problems but doesn't really offer any solution or improvement. Given for some problems listed it's really hard to find a plausible solution, I would prefer an answer where author at least tries to provide a solution, so it will be sort of a ...


2

PDO has some rather handy fetching options. FETCH_GROUP is good for grouping the first level (product categories), but some extra handling is necessary to group the second level (product name-sizes). To perform this nested grouping, I'll show the implementation of a temporary variable to track whether or not the current iteration is processing a new group ...


2

Assuming that you are trying to extract ALL of the rating values from your table, I agree with Unnamed that you should simply GROUP BY and return the Rating, and the COUNT() in the result set. Two things to add here... Without apply default values, you need to be aware that Unnamed's query will potentially deliver gaps where there is no count for a ...


2

Error handling if response.status_code != 200: print('api response error: {}'.format(response)) return is better represented as a simple call to response.raise_for_status(). Also, this: try: response_payload = response.json() except ValueError: return is dangerous. Silently failing should (at the least) be left up to the caller to decide ...


2

You got the SQL part quite well. If you only had been as careful when generating the HTML. At the very least, you should wrap every bit of output through htmlspecialchars. I'm sure there are better ways, but that's the basic building block, and you should learn it. function html_println($label, $value) { echo htmlspecialchars($label) . ": " . ...


Only top voted, non community-wiki answers of a minimum length are eligible