|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On April 24 2013 17:33 FFGenerations wrote: hey, i have to rush off now, but perhaps one of you would fancy answering a question?
<snip>
<?php
$connection = mysql_connect("localhost", "jon1", "password");
mysql_select_db("takeaway");
$result = mysql_query("SELECT * FROM products");
<snip>
One thing you *ALWAYS* want to do is select by columns instead of * (all) and you also always want to use a group by column. While you might always get the same ordering, it's bound to go weird at some point if you don't use group by. While select * is the same as selecting all the columns you need, it's more obvious what you want to use from the database when you have the column names - small things that makes life easier
|
On April 25 2013 21:32 bangsholt wrote:Show nested quote +On April 24 2013 17:33 FFGenerations wrote: hey, i have to rush off now, but perhaps one of you would fancy answering a question?
<snip>
<?php
$connection = mysql_connect("localhost", "jon1", "password");
mysql_select_db("takeaway");
$result = mysql_query("SELECT * FROM products");
<snip>
One thing you *ALWAYS* want to do is select by columns instead of * (all) and you also always want to use a group by column. While you might always get the same ordering, it's bound to go weird at some point if you don't use group by. While select * is the same as selecting all the columns you need, it's more obvious what you want to use from the database when you have the column names - small things that makes life easier 
Using Group By makes absolute no sense
|
On April 25 2013 22:02 Yoshi- wrote:Show nested quote +On April 25 2013 21:32 bangsholt wrote:On April 24 2013 17:33 FFGenerations wrote: hey, i have to rush off now, but perhaps one of you would fancy answering a question?
<snip>
<?php
$connection = mysql_connect("localhost", "jon1", "password");
mysql_select_db("takeaway");
$result = mysql_query("SELECT * FROM products");
<snip>
One thing you *ALWAYS* want to do is select by columns instead of * (all) and you also always want to use a group by column. While you might always get the same ordering, it's bound to go weird at some point if you don't use group by. While select * is the same as selecting all the columns you need, it's more obvious what you want to use from the database when you have the column names - small things that makes life easier  Using Group By makes absolute no sense Pretty sure he meant "Order By".
|
On April 25 2013 22:03 Tobberoth wrote:Show nested quote +On April 25 2013 22:02 Yoshi- wrote:On April 25 2013 21:32 bangsholt wrote:On April 24 2013 17:33 FFGenerations wrote: hey, i have to rush off now, but perhaps one of you would fancy answering a question?
<snip>
<?php
$connection = mysql_connect("localhost", "jon1", "password");
mysql_select_db("takeaway");
$result = mysql_query("SELECT * FROM products");
<snip>
One thing you *ALWAYS* want to do is select by columns instead of * (all) and you also always want to use a group by column. While you might always get the same ordering, it's bound to go weird at some point if you don't use group by. While select * is the same as selecting all the columns you need, it's more obvious what you want to use from the database when you have the column names - small things that makes life easier  Using Group By makes absolute no sense Pretty sure he meant "Order By".
Even that makes only sense, when it is needed
|
On April 25 2013 21:32 bangsholt wrote:Show nested quote +On April 24 2013 17:33 FFGenerations wrote: hey, i have to rush off now, but perhaps one of you would fancy answering a question?
<snip>
<?php
$connection = mysql_connect("localhost", "jon1", "password");
mysql_select_db("takeaway");
$result = mysql_query("SELECT * FROM products");
<snip>
One thing you *ALWAYS* want to do is select by columns instead of * (all) and you also always want to use a group by column. While you might always get the same ordering, it's bound to go weird at some point if you don't use group by. While select * is the same as selecting all the columns you need, it's more obvious what you want to use from the database when you have the column names - small things that makes life easier 
Assuming you mean ORDER BY, always using ORDER BY makes no sense since in a lot of cases you don't care at all about the order of the results, you usually just want to know which items there are, so forcing the extra work on the server to order it is counterproductive. Even if a sort on an already sorted list is usually O(1) it's still extra work for the server.
I agree about writing the column names instead of * though, it makes working with the result a lot easier. Especially after picking up code a week later you don't have to dig in the database to figure out again which columns were in that specific table. It's also helpful when working with a legacy database without consistent naming schemes since you don't have to remember wether this table had the id as "id" or "table_id". Lastly, it can reduce the load to always just fetch just the columns you really need to fetch. If you just need the ID column, the server doesn't have to keep the whole row in memory but can instead just store that one value per row. It's a good habit to develop and while it's a little more to write it still saves a lot of time.
|
There should be a feature in all databases, if you don't use order by, your results will be scrambled 5% of the time.
It IS a strain on the database - but before you have an almost finished API/Program/App you shouldn't do "optimization", which is the only argument I can see for not always using order by.
|
On April 25 2013 22:49 bangsholt wrote: There should be a feature in all databases, if you don't use order by, your results will be scrambled 5% of the time.
It IS a strain on the database - but before you have an almost finished API/Program/App you shouldn't do "optimization", which is the only argument I can see for not always using order by.
And the argument for using order by even when it is absolute not needed is?
|
On April 25 2013 21:32 icystorage wrote:Show nested quote +On April 25 2013 21:20 mcc wrote:On April 25 2013 19:29 Morfildur wrote:On April 25 2013 17:11 billy5000 wrote:On April 24 2013 11:51 white_horse wrote: Is it possible to teach yourself HTML and be pretty good at it? I'm planning on studying intensively on my own this summer.
Also, should I learn HTML first or PHP, or should I study both at the same time? Any reason why you want to learn php? I'm not here to criticize--I'm fairly new to web development myself (getting the hang of play framework atm)--but I'm just wondering what made you choose php over other popular frameworks, such as rails and django. I for one chose play because I was learning scala on the side. Thought it would be a good idea to do something with what I've learned. I also have a project in mind. Note: I know it's wrong to consider php a web framework, but you know what I mean  . I'm just not familiar with any popular php frameworks. There is one reason why PHP is a common choice to learn: It's what everyone uses, so it provides the best job opportunities. Yes, it's a horrible language and i don't like it but if you look at it from a real-world perspective, making code look pretty doesn't matter, results matter. That is what PHP has: Results. I recommend to read PHP Sucks, But It Doesn't Matter from the blog of Jeff Atwood who explains it better than i can. PHP, Python, Ruby, Scala, the choice of language doesn't matter in the end, only results do. Bad coders write bad code in every language. On April 24 2013 17:55 tec27 wrote:On April 24 2013 17:33 FFGenerations wrote:hey, i have to rush off now, but perhaps one of you would fancy answering a question? i am printing contents of my product table to a webpage (menu of food items) my tutor used While to do this but i dont really know why, or why you cant use Foreach i dont need a 100% answer, just a very general answer would be sufficient for me to see how my understanding lacks (i am total beginner). something like "they both work completely different and you need to study up on them properly to know why and how" + Show Spoiler +
<?php
$connection = mysql_connect("localhost", "jon1", "password");
mysql_select_db("takeaway");
$result = mysql_query("SELECT * FROM products");
while($row = mysql_fetch_array($result)) { echo "<strong>Name:</strong> " . $row["productname"] . "<br />";
echo "<a href='item.php?productid=" . $row["productid"] . "'>Details</a><br/>"; }
foreach($row = mysql_fetch_array($result)) { echo "<strong>Name:</strong> " . $row["productname"] . "<br />";
echo "<a href='item.php?productid=" . $row["productid"] . "'>Details</a><br/>"; }
?>
(the foreach doesnt work fyi. i have to fuck off now for 2 hours but will be back to have another look) Firstly, quit using the mysql library, its awful and deprecated. Use mysqli or PDO instead. ***snip*** I wholeheartedly agree. PDO is so much better than the standard mysql_* functions and only a tiny bit more complex. Coming originally from Perl with it's DBI library, it feels a lot more natural to me as well. Anyone who still uses mysql_* deserves a strong kick in the lower body region. I disagree with such generalized statement as "bad coders write bad code in any language". Quality of code is not binary measure. And languages influence how bad the code can get. Plus all programmers write bad code to some degree, good language helps you avoid some of that. Bad code is unavoidable, if language can prevent some of it, that language is better. Of course there is balance to be had between how much language constricts you without actually preventing you to use useful techniques. PHP is terrible language and it matters (even though not to some very big degree). But which languages are used is not based on quality or even pure usefulness of the language, but on factors independent of the language itself (libraries, frameworks, community, support, ...). Basically PHP has results, because it is popular, simple feedback loop. That is not to discourage someone from learning PHP, but if they are not pressed to start with it by necessity of earning money or something, it is not ideal first language, not even for creating web pages. out of curiosity, what is ideal in creating web pages? I would like to point out that I meant "not even first language for creating web pages". Point is that if you are not necessarily selling your work, other languages are better at learning programming in general and they can also be reasonably used to create webpages. As for "ideal" language for creating webpages in practice, there isn't one. For example my favourite C#/ASP has issues with servers. Mono is not ideal so you might be limited to Windows servers. Also if your projects is not that big it might be better handled by simple PHP project.
|
On April 25 2013 22:49 bangsholt wrote: There should be a feature in all databases, if you don't use order by, your results will be scrambled 5% of the time.
It IS a strain on the database - but before you have an almost finished API/Program/App you shouldn't do "optimization", which is the only argument I can see for not always using order by. When I do not absolutely care about order, why should I use it. It is actually very bad advice. You should basically NEVER use ORDER BY unless you really need the data ordered for whatever reason. Always using order by makes you used to that and if you later need to remove it because the query is unnecessarily slow you might actually break your whole code.
|
Error 40 from my site. Use Order By when order matters - i.e. in the context menu that's being generated from that script. I suppose we agree now - it's better to use Order By when order matters, rather than rely on the database to sort your rows correctly.
|
On April 25 2013 23:07 bangsholt wrote: Error 40 from my site. Use Order By when order matters - i.e. in the context menu that's being generated from that script. I suppose we agree now - it's better to use Order By when order matters, rather than rely on the database to sort your rows correctly. Well if you require ordering than yes, you should not rely on the db's default order. But why do you think this is the case here, for me it does not look like it is necessarily the case.
|
On April 25 2013 23:07 bangsholt wrote: Error 40 from my site. Use Order By when order matters - i.e. in the context menu that's being generated from that script. I suppose we agree now - it's better to use Order By when order matters, rather than rely on the database to sort your rows correctly.
Yes, if you need your data in a specific order you should use ORDER BY.
However, your quote was:
On April 25 2013 21:32 bangsholt wrote: *snip* One thing you *ALWAYS* want to do is select by columns instead of * (all) and you also always want to use a order by column. *snip*
(fixed the group/order mixup since group by makes even less sense in that context)
In a lot of cases you do not care about the order at all, so there is no reason to ever have ORDER BY for those cases. For example in the last company we did a lot of "Give me all the codecs and their properties that we have this movie in" queries. It didn't matter what those codecs were, it didn't matter which order they were in, we only needed all the results. Ordering would only have put more load on the database that already was at it's limits.
|
Ok so I'm trying to learn a bit of Perl, figured it would come in handy.
Anyway it turns out that VS2010 has sheltered me from the horrors of Eclipse, I'm using the EPIC plugin and for the life of me I can't find my locals when debugging:
![[image loading]](http://i.imgur.com/PPQswCf.png)
Can anyone shed some light on this? I installed PadWalker using PPM as it recommends but this doesn't appear to help. Considering how easy VS2010 makes debugging straightforward stuff I'm slightly annoyed, even WinDbg is easier to use than this >.<
|
On April 25 2013 23:54 adwodon wrote:Ok so I'm trying to learn a bit of Perl, figured it would come in handy. Anyway it turns out that VS2010 has sheltered me from the horrors of Eclipse, I'm using the EPIC plugin and for the life of me I can't find my locals when debugging: + Show Spoiler +Can anyone shed some light on this? I installed PadWalker using PPM as it recommends but this doesn't appear to help. Considering how easy VS2010 makes debugging straightforward stuff I'm slightly annoyed, even WinDbg is easier to use than this >.<
I can't help you with that problem, but as a Perl veteran i can give you the most important tip any new Perl programmer needs to know: "use strict", always "use strict".
Get in the habit of using it even for the smallest scripts.
|
On April 25 2013 19:29 Morfildur wrote:Show nested quote +On April 25 2013 17:11 billy5000 wrote:On April 24 2013 11:51 white_horse wrote: Is it possible to teach yourself HTML and be pretty good at it? I'm planning on studying intensively on my own this summer.
Also, should I learn HTML first or PHP, or should I study both at the same time? Any reason why you want to learn php? I'm not here to criticize--I'm fairly new to web development myself (getting the hang of play framework atm)--but I'm just wondering what made you choose php over other popular frameworks, such as rails and django. I for one chose play because I was learning scala on the side. Thought it would be a good idea to do something with what I've learned. I also have a project in mind. Note: I know it's wrong to consider php a web framework, but you know what I mean  . I'm just not familiar with any popular php frameworks. There is one reason why PHP is a common choice to learn: It's what everyone uses, so it provides the best job opportunities. Yes, it's a horrible language and i don't like it but if you look at it from a real-world perspective, making code look pretty doesn't matter, results matter. That is what PHP has: Results. I recommend to read PHP Sucks, But It Doesn't Matter from the blog of Jeff Atwood who explains it better than i can. PHP, Python, Ruby, Scala, the choice of language doesn't matter in the end, only results do. Bad coders write bad code in every language. I thought I was just a mess PHP user. After reading that I guess it makes sense that others are messy with combining html and php too.
|
On April 26 2013 00:38 obesechicken13 wrote:Show nested quote +On April 25 2013 19:29 Morfildur wrote:On April 25 2013 17:11 billy5000 wrote:On April 24 2013 11:51 white_horse wrote: Is it possible to teach yourself HTML and be pretty good at it? I'm planning on studying intensively on my own this summer.
Also, should I learn HTML first or PHP, or should I study both at the same time? Any reason why you want to learn php? I'm not here to criticize--I'm fairly new to web development myself (getting the hang of play framework atm)--but I'm just wondering what made you choose php over other popular frameworks, such as rails and django. I for one chose play because I was learning scala on the side. Thought it would be a good idea to do something with what I've learned. I also have a project in mind. Note: I know it's wrong to consider php a web framework, but you know what I mean  . I'm just not familiar with any popular php frameworks. There is one reason why PHP is a common choice to learn: It's what everyone uses, so it provides the best job opportunities. Yes, it's a horrible language and i don't like it but if you look at it from a real-world perspective, making code look pretty doesn't matter, results matter. That is what PHP has: Results. I recommend to read PHP Sucks, But It Doesn't Matter from the blog of Jeff Atwood who explains it better than i can. PHP, Python, Ruby, Scala, the choice of language doesn't matter in the end, only results do. Bad coders write bad code in every language. I thought I was just a mess PHP user. After reading that I guess it makes sense that others are messy with combining html and php too.
It depends. PHP is a messy language and it's really easy to create a mess in it. Even the PHP creator says so (Go to around 1:03:00 and listen in for 2-3 minutes and you should hear what i reference).
However, that doesn't mean that we as programmers shouldn't strive to write clean code with it. PHP has the neccessary capabilities for clean code, most people just tend to not use them.
Either way, in the end the poorly programmed application that actually gets finished is worth more than perfect code that never gets completed.
|
1019 Posts
Can one of you guys explain how PHP relates to html?
|
Hyrule18982 Posts
Basically, not at all.
HTML (in conjunction with CSS) tells the browser how to display content.
PHP does stuff server side as an actual program.
PHP can output HTML, which is handy for creating dynamic web pages. But PHP can also output other forms of data, including non-text, which enables things like image editing and Battle.net bots.
|
On April 26 2013 01:25 white_horse wrote: Can one of you guys explain how PHP relates to html?
That is a hard to answer question.
Serverside programming languages (i.e. not javascript inside the browser) just generate HTML code that they then send to the user. You can do the same in Python, Ruby, Java, C#, even C if you want to. All that the server side does is to generate HTML and send the end result back, there is no direct interaction.
HTML is a layout language, it only describes how the stuff should look. It has no logic, no loops and no branches (if/else).
PHP was designed to make the generation of HTML easier by adding server side loops and such in between normal HTML pages, so the creator inverted the normal layout of programming languages ("Everything is code unless declared otherwise") to consider everything as something to send to the user unless it was in a specific tag. It still happens server side and is invisible to the user, i.e. there is no further interaction after sending the HTML. PHP can send everything though, it's not limited to HTML, it's just the way it's commonly used.
Classic programming pseudocode:
String output = " <html> <body> this is html. ";
foreach (item in items) // assuming an array "items" with an unknown amount of items { output += " and this gets added in a loop "; } output += " </body> </html> ";
PHP pseudocode:
<html> <body> this is html. <? foreach ($items as $item) { ?> and this gets added in a loop <? } ?> </body> </html>
What the user sees:
<html> <body> this is html. and this gets added in a loop. and this gets added in a loop. and this gets added in a loop. ... and this gets added in a loop. </body> </html>
Generally, this is a messy way to program, which is why most programmers use a template engine or dedicate a specific part of code to generate the HTML output while they keep the logic as far away as possible from it. It could the same way be used to write simple, unformatted text, a LaTeX document or some other format.
In short: PHP is not related to HTML.
|
On April 25 2013 23:43 Morfildur wrote
In a lot of cases you do not care about the order at all, so there is no reason to ever have ORDER BY for those cases. For example in the last company we did a lot of "Give me all the codecs and their properties that we have this movie in" queries. It didn't matter what those codecs were, it didn't matter which order they were in, we only needed all the results. Ordering would only have put more load on the database that already was at it's limits.
It becomes even more important if your request is on large data. Codecs for a movie is a pretty small set. But if you're requesting like a billion rows of data, sorting may add a loooong time to your request.
Doing extra work to get an O(nlogn) operation when the lazier solution was O(n)...
|
|
|
|