Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=DrTaxi;45515622]It's not exactly uncommon.
Like in this very form I'm writing this post in:
[code]<form class="vbform" name="quick_reply" id="quick_reply" method="post" action="newreply.php?do=postreply&t=1250244"
[...]
[/code][/QUOTE]
But again, I doubt it is meant to happen that way. In NodeJS (but as far as I know, other languages have the same method of working), you have routes. So you can route a POST request to [url]http://website.com/path/to/my/route[/url] and then handle a POST request in that file. I suppose that people try to achieve that same thing (Twitter API, i.e.), but that is not mixing up GET and POST. You are just pointing your POST request to a route, and since PHP doesn't have such a thing, it works different.
Either way, just because big projects use it (vBulletin, i.e.) doesn't mean it is supposed to happen. It might be common to happen, but I'd say it's bad software design if you can't do it without.
[QUOTE=Cyberuben;45516024]But again, I doubt it is meant to happen that way. In NodeJS (but as far as I know, other languages have the same method of working), you have routes. So you can route a POST request to [url]http://website.com/path/to/my/route[/url] and then handle a POST request in that file. I suppose that people try to achieve that same thing (Twitter API, i.e.), but that is not mixing up GET and POST. You are just pointing your POST request to a route, and since PHP doesn't have such a thing, it works different.
Either way, just because big projects use it (vBulletin, i.e.) doesn't mean it is supposed to happen. It might be common to happen, but I'd say it's bad software design if you can't do it without.[/QUOTE]
Ugh, that's framework features you're talking about. They exist in PHP aswell.
And tell me, why is it so bad to combine POST and GET huh? In PHP, GET is the only method you can share easily with a URL. Most apps are structured with index as the controller, e.g index.php?page=login. This way you can send index.php?page=login to other people and they'll wind up on the login page, where the login form should definitely send a POST request to index.php?do=login or whatever. This is what makes Object Oriented PHP so much easier to work with.
You're just talking from personal opinion here, and that won't get you far.
[QUOTE=Cyberuben;45516024]Either way, just because big projects use it (vBulletin, i.e.) doesn't mean it is supposed to happen. It might be common to happen, but I'd say it's bad software design if you can't do it without.[/QUOTE]
What you see there is pretty much how they used to write PHP before the PHP-users joined the routing frameworks craze.
[QUOTE=Cyberuben;45516024]So you can route a POST request to [url]http://website.com/path/to/my/route[/url] and then handle a POST request in that file.[/QUOTE]
You might want to get to know what HTTP URLs and a RESTful architecture are (and how they are different) before you get to objurgate anyone about them.
[QUOTE=Cyberuben;45516024]But again, I doubt it is meant to happen that way. In NodeJS (but as far as I know, other languages have the same method of working), you have routes. So you can route a POST request to [url]http://website.com/path/to/my/route[/url] and then handle a POST request in that file. I suppose that people try to achieve that same thing (Twitter API, i.e.), but that is not mixing up GET and POST. You are just pointing your POST request to a route, and since PHP doesn't have such a thing, it works different.
Either way, just because big projects use it (vBulletin, i.e.) doesn't mean it is supposed to happen. It might be common to happen, but I'd say it's bad software design if you can't do it without.[/QUOTE]
You [I]do[/I] realize that if you're doing URLs like that, chances are that you're backing them with a single index.php file and using URL rewrites to make them pretty, meaning you are probably using $_GET to get at the request URL at some point anyways and it's probably just been abstracted by your framework.
It's not bad software design when it's the primary way to access data in a URL that's provided by the language lol.
[quote]In NodeJS (but as far as I know, other languages have the same method of working), you have routes.[/quote]
If you don't actually understand how this works in PHP/PHP frameworks you shouldn't really be preaching about it haha. What you are saying is "better" is exactly the same as the PHP version you are decrying, it's just handled in a different way by the languages and frameworks that you're using. Node actually doesn't come with a router out of the box either, btw.
I was in the wrong here, sorry. Though, doesn't change my opinion in on it looking weird.
Alright. So I have made this awesome, 10MB tutorial that I want to force down my user's throats because I love them, but I only want to execute it once.
What would be the best way to store who has seen it and who hasn't?
-Storing it on a cookie (which would suck if the user ever clears cookies). tbh I'm only listing it because it [I]is [/I]an option.
-Make a new field on the users table, 'tutorial', and do a check to see if it's NULL or not.
-Make a new table, which brings two options
--Add a row when the user watches it, check against it to see if he hasn't. Allows for more than one tutorial, but will get quite heavy in the future I guess.
--Add a row at registration, and remove it when the user watches it. However, people that don't go to the intended page will keep another row there. Plus, as of right now, I'd have to add more than 2k rows (since nobody has seen it yet).
I'm open to other suggestions, of course.
[QUOTE=Coment;45528970]Alright. So I have made this awesome, 10MB tutorial that I want to force down my user's throats because I love them, but I only want to execute it once.
What would be the best way to store who has seen it and who hasn't?
-Storing it on a cookie (which would suck if the user ever clears cookies). tbh I'm only listing it because it [I]is [/I]an option.
-Make a new field on the users table, 'tutorial', and do a check to see if it's NULL or not.
-Make a new table, which brings two options
--Add a row when the user watches it, check against it to see if he hasn't. Allows for more than one tutorial, but will get quite heavy in the future I guess.
--Add a row at registration, and remove it when the user watches it. However, people that don't go to the intended page will keep another row there. Plus, as of right now, I'd have to add more than 2k rows (since nobody has seen it yet).
I'm open to other suggestions, of course.[/QUOTE]
2k rows is nothing for MySQL. It can easily hold millions.
[QUOTE=Cyberuben;45529810]2k rows is nothing for MySQL. It can easily hold millions.[/QUOTE]
And with proper indexes and careful query and structure planning, billions.
I worked on a webgame that had a few million rows for items. It was originally made by a bunch of 15 year olds, and was some of the worst PHP I've ever read.
But MySQL handled it like a champ.
Well I've come across an issue. Basically I need to create and update a text file on the fly with Heroku but it has a read only filesystem. I checked out Amazon S3 but with only 2,000 PUT requests that seems like a very small amount for something that needs to be updated fairly constantly.
So far the two things that require updating are a logs text file and a messages text file. The messages in particular worry me because unless I'm reading this wrong, it would only support 2,000 updates (or messages) until it maxes out.
Is there an alternative to this or am I out of luck?
What's the best way to create models in rails that are identical except in table name? Obviously I don't want to just duplicate all of the code. The distinction between the tables is that they are for days, weeks and months but they will otherwise have identical logic in every aspect.
Here's the schema of the day table, for example:
[code] create_table "daygains", :primary_key => "ID", :force => true do |t|
t.integer "Overall", :null => false
t.integer "Attack", :null => false
t.integer "Defence", :null => false
t.integer "Strength", :null => false
t.integer "Hitpoints", :null => false
t.integer "Ranged", :null => false
t.integer "Prayer", :null => false
t.integer "Magic", :null => false
t.integer "Cooking", :null => false
t.integer "Woodcutting", :null => false
t.integer "Fletching", :null => false
t.integer "Fishing", :null => false
t.integer "Firemaking", :null => false
t.integer "Crafting", :null => false
t.integer "Smithing", :null => false
t.integer "Mining", :null => false
t.integer "Herblore", :null => false
t.integer "Agility", :null => false
t.integer "Thieving", :null => false
t.integer "Slayer", :null => false
t.integer "Farming", :null => false
t.integer "Runecrafting", :null => false
t.integer "Hunter", :null => false
t.integer "Construction", :null => false
t.float "EHP", :limit => 7, :null => false
end[/code]
[QUOTE=WitheredGryphon;45536553]Well I've come across an issue. Basically I need to create and update a text file on the fly with Heroku but it has a read only filesystem. I checked out Amazon S3 but with only 2,000 PUT requests that seems like a very small amount for something that needs to be updated fairly constantly.
So far the two things that require updating are a logs text file and a messages text file. The messages in particular worry me because unless I'm reading this wrong, it would only support 2,000 updates (or messages) until it maxes out.
Is there an alternative to this or am I out of luck?[/QUOTE]
Why does it need to be a text file instead of a database table? You could always get a VPS and not do it on heroku if you really do need it to be a file.
[editline]29th July 2014[/editline]
[QUOTE=sambooo;45536683]What's the best way to create models in rails that are identical except in table name? Obviously I don't want to just duplicate all of the code. The distinction between the tables is that they are for days, weeks and months but they will otherwise have identical logic in every aspect.
Here's the schema of the day table, for example:
[code] create_table "daygains", :primary_key => "ID", :force => true do |t|
t.integer "Overall", :null => false
t.integer "Attack", :null => false
t.integer "Defence", :null => false
t.integer "Strength", :null => false
t.integer "Hitpoints", :null => false
t.integer "Ranged", :null => false
t.integer "Prayer", :null => false
t.integer "Magic", :null => false
t.integer "Cooking", :null => false
t.integer "Woodcutting", :null => false
t.integer "Fletching", :null => false
t.integer "Fishing", :null => false
t.integer "Firemaking", :null => false
t.integer "Crafting", :null => false
t.integer "Smithing", :null => false
t.integer "Mining", :null => false
t.integer "Herblore", :null => false
t.integer "Agility", :null => false
t.integer "Thieving", :null => false
t.integer "Slayer", :null => false
t.integer "Farming", :null => false
t.integer "Runecrafting", :null => false
t.integer "Hunter", :null => false
t.integer "Construction", :null => false
t.float "EHP", :limit => 7, :null => false
end[/code][/QUOTE]
Look up Single Table Inheritance and thank me later :)
I'm not able to modify the tables to add a 'type' column, nor am I able to merge all three tables into one table with a type column because I'm porting a live PHP application to rails. Correct me if I'm wrong but I can't use STI here can I?
To elaborate further on my app, I have a Player model that among other things should have one of each of day/week/monthgains that are calculated and updated when the Player is updated.
[editline]29th July 2014[/editline]
See: [url]http://duk.im/tracker/currenttop.php[/url] for an example of what the results are being used for if it helps.
[QUOTE=KmartSqrl;45537134]Why does it need to be a text file instead of a database table? You could always get a VPS and not do it on heroku if you really do need it to be a file.[/quote]
Yeah I started thinking about storing it in a database after I posted. I'll just have to get a lot more familiar with MySQL I suppose.
[QUOTE=sambooo;45537427]I'm not able to modify the tables to add a 'type' column, nor am I able to merge all three tables into one table with a type column because I'm porting a live PHP application to rails. Correct me if I'm wrong but I can't use STI here can I?
To elaborate further on my app, I have a Player model that among other things should have one of each of day/week/monthgains that are calculated and updated when the Player is updated.
[editline]29th July 2014[/editline]
See: [url]http://duk.im/tracker/currenttop.php[/url] for an example of what the results are being used for if it helps.[/QUOTE]
Why does porting an application mean that you cant modify the DB tables? At some point you're going to have to take the php app down and put the rails one up, right? So couldn't you just update the tables then?
You are correct that you wouldn't be able to use STI under those circumstances though.
[editline]29th July 2014[/editline]
[QUOTE=WitheredGryphon;45537476]Yeah I started thinking about storing it in a database after I posted. I'll just have to get a lot more familiar with MySQL I suppose.[/QUOTE]
I'd do postgres instead of mysql.
[QUOTE=KmartSqrl;45537576]
I'd do postgres instead of mysql.[/QUOTE]
How hard is it to convert from MySQL to Postgres? Cause I've written this entire project using MySQL (I'm not at all familiar with Postgres).
It's pretty easy. You probably won't have to worry about much other than changing checks on boolean fields from 1/0 to true/false. Might not be worth switching if you've got it started already though.
[QUOTE=KmartSqrl;45537634]It's pretty easy. You probably won't have to worry about much other than changing checks on boolean fields from 1/0 to true/false. Might not be worth switching if you've got it started already though.[/QUOTE]
I might look into it later if it isn't too difficult to get switched over. Like I said though this entire project was written with MySQL.
Is the connection technique through PHP and everything still the same?
[QUOTE=KmartSqrl;45537576]Why does porting an application mean that you cant modify the DB tables? At some point you're going to have to take the php app down and put the rails one up, right? So couldn't you just update the tables then?
You are correct that you wouldn't be able to use STI under those circumstances though.[/QUOTE]
I'm currently talking to the lead developer and trying to convince him to change the current tables over to STI format. I know I could just update the tables for my app but while I'm developing I'm actually using copies of the live database as sample data so I'd like to maintain parity there.
Here's hoping he'll be willing.
[QUOTE=sambooo;45537809]I'm currently talking to the lead developer and trying to convince him to change the current tables over to STI format. I know I could just update the tables for my app but while I'm developing I'm actually using copies of the live database as sample data so I'd like to maintain parity there.
Here's hoping he'll be willing.[/QUOTE]
I bet you could whip together a script to transform those live tables to the format you really want them in pretty easily so you could still keep parity while you're doing your dev (and then you could just use that same script to change the live ones when it's time for the switch)
IMO, it's really bad to follow the design of a legacy system just because it's the legacy system. If you're rebuilding/redesigning things you should be taking a real look at [B]everything[/B] while you have the chance, because you're unlikely to get another really good time to do it.
[QUOTE=KmartSqrl;45537866]I bet you could whip together a script to transform those live tables to the format you really want them in pretty easily so you could still keep parity while you're doing your dev (and then you could just use that same script to change the live ones when it's time for the switch)
IMO, it's really bad to follow the design of a legacy system just because it's the legacy system. If you're rebuilding/redesigning things you should be taking a real look at [B]everything[/B] while you have the chance, because you're unlikely to get another really good time to do it.[/QUOTE]
I did take a shot at modifying the current production code to be STI friendly but then I had to try to figure out what the hell is going on [url=https://github.com/FootKjott/tracker/blob/837edf5d0b6d0e78b67726e29ec6397ea8c08820/include/virtual_list.php#L166]here[/url] among other things and decided it is definitely not worth the time.
I'll try to write a script to transform the tables, hopefully it isn't slow because the live site can't go down for long before annoying players. Thanks for your advice!
[editline]30th July 2014[/editline]
Ok the entire set migrates in under a second, that's fast enough
[QUOTE=WitheredGryphon;45537700]I might look into it later if it isn't too difficult to get switched over. Like I said though this entire project was written with MySQL.
Is the connection technique through PHP and everything still the same?[/QUOTE]
Postgres' authentication mechanism etc. are a little different.
But that's a couple lines of code, nothing to worry about.
As for the rest, SQL is mostly standardized - you probably aren't using a lot of MySQL-specific features, if any.
If your application is fully covered in unit tests, you might as well just try dumping your database and importing it into Postgres verbatim, then switching the code over :v:
Anyony here ever used Azure to publish ASP.NET applications?
My server really needs to be replaced.
how do I make my PHP show numbers normally and not as:
7.6561198044641E+16
?
[QUOTE=01271;45568866]how do I make my PHP show numbers normally and not as:
7.6561198044641E+16
?[/QUOTE]
That's a number in exponential form; wolframAlpha tells me this is equal to 76,561,198,044,641,000, or just over 76 quadrillion (76 quadrillion, 561 trillion, 198 billion, 44 million, and 641 thousand to be exact).
The reason PHP may be displaying the number like that is because a) it's too large to fit as a regular integer, or b) it might be easier to display it as that number.
[QUOTE=01271;45568866]how do I make my PHP show numbers normally and not as:
7.6561198044641E+16
?[/QUOTE]
[code]
echo number_format(7.6561198044641E+16, 0, '', '');
//Output: 76561198044640992
[/code]
PHP will show the number normally on some distributions while on others it will not, is there just a php.ini configuration it can use?
[QUOTE=01271;45569586]PHP will show the number normally on some distributions while on others it will not, is there just a php.ini configuration it can use?[/QUOTE]
No I'm afraid there isn't.
[QUOTE=Svenskunganka;45569288][code]
echo number_format(7.6561198044641E+16, 0, '', '');
//Output: 76561198044640992
[/code][/QUOTE]
7.6561198044641E+16 doesn't equal 76561198044640992.
7.6561198044641E+16 means 7.6561198044641*10^16, which is, as Ac!dL3ak says, 76561198044641000.
You're going to need something like the BCMath library to calculate massive numbers like this one.
Hey,
On my DEV site which is [URL="http://development.jonathanmaby.co.uk/index.php"]here[/URL], how can I position the 'WELCOME' box UNDER the slide show? I've tried all sorts of things. Right click to view source code, I would post here but I'm out at the moment.
P.S Moofy please don't be mad at me for posting this D:
[QUOTE=ENG.jonny;45571138]P.S Moofy please don't be mad at me for posting this D:[/QUOTE]
What
Sorry, you need to Log In to post a reply to this thread.