Each time I post some info from my web app to the server i send it to a PHP file. this php file then calls a function that put the info into the database. This is the general idea right ? 🙂
The only problem is that I find myself creating a php file for each function call! I have one for creating a “task”, one for creating a “user” one for toggleing a variable, one for setting a variable …..etc.
I don’t know how else to do it. Even though I keep all my PHP database functions in one file, I find that I have to make a new file for each post call I do.
Example 1:
<?php
include 'databasefunctions.php';
inserttaskDB();
?>-
Example 2:
<?php
include 'databasefunctions.php';
inserthelpoffers($_POST[task_id],$_SESSION[id],$_POST[help_offer]);
?>
I find that I’m organizing my code badly. How can I better organize my code?
I think I know what you are doing. When you send a post request to a php page via your app ypu call a function in that file to store the data into db. The problem seems to be you send this post request to multiple PHP files instead of one. So here is a quick fix for this.
Now what you can do is have only one file like getDataFromMobile.php
so when you send data to getDataFromMobile send one more variable called func(for function)
This is a very quick fix. I personally would tend towards OOP in such cases.
Hope this helps,
Dins