-4

I'm building a penny-auction platform like DealDash and just read into the WebSocket and node.js topic. I used PHP, MySQL and Ajax to build the website. I'm nearly finished and just have to implement the WebSocket function for the auctions to display correctly for all users.

I found a script to help me getting started with node.js and mysql, so I can still retrieve the data from my database every second. Because I need the auction timer and price to be displayed asynchronously for all users. Because I also have to complete this project in some days. But I'm considering learning more about NoSQL-db's and node.js, etc. afterwards of course.

However I've managed to have all auction items updated on the starting page async. with multiple browsers. So changes are updated for every user like I wanted it to be.

Now every auction has a single page to get further details to an auction and to the product. And usually I used $_GET['id'] in PHP/MySQL to receive the needed data which specific auction this is. But the node.js server-file server.js is the file to SELECT * FROM db.

So here's my problem. Do I have to tell the server-file, if the user is on an specific auction-id-page it has to make another specific query? I can't image that, because other projects like a social network would've dozens of specific queries, all written in the node.js server-file? Also using an if-else statement in the server-file doesn't seem right? Also I don't know how I would get this specific id of an auction.

I'm just confused about the right way to realize something like that, because I'm so used to PHP/MySQL/Ajax and hope you could help me with that.

closed as unclear what you're asking by user40980, Ixrec, Ampt, GlenH7, gnat Apr 27 '15 at 16:55

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

-1

Well, for such a "complex" project, i suggest that you split up your domains into smaller pieces, call it modules. Maybe it is easier to work with apis/resources instead of direct queries to the database.

Let me explain this a bit. Let's assume you want a front end part and a backend part. The front-end and the backend talks over an API, in my case a REST api. Let's say you want to display the information for auction number #2522. Your front-end logic makes a get request to your backend like:

GET api.myauctionpage.com/auction/2522.

The backend now has the responsibility to translate your get request into database queries and gathering informationen. If its done, it send the information to the client in a machine readable way (e.g. JSON, XML...).

For instance the return for the get request above would be something like:

{id: 2522, current_price: 25.00, betters: [{better_id: 123, better_name: 'charly'}, {better_id: 963, better_name: 'christine101'}]}

The front page logic now has the data and can starting to put it into the page and display it to the customer. In our case the current price is 25.00 and there are two betters, charly and christine101.

You see, I decoupled the logics and the backend does not care who the information wants and the frontend does not care how he gets the information.

Now it is up to you how you use or combine the api with your frontend, if you request every informationen every second or if you want to update it with websocket "events".

The backend can be written in PHP or even JavaScript (+node.js) or both, as long as the front end has a unique and correct way to request the informationen.

Not the answer you're looking for? Browse other questions tagged or ask your own question.