Heller,
I'm working on a plugin and I've just totally hit a wall. I'm wanting to create a plugin, if you will, for wordpress where the user that's logged in would be able to navigate to, select an option from a dropdown menu, hit a button and have an entry added to a db. I'm wanting two databases created on the initial button click and then every button click after would append to the database that corresponds to the current user and the option selected. So, for example let's say I have Joe Smith. He logs in and navigates to, let's call it "Time Clock" in the wp menu. Upon loading, he has the option to select the location he is at and click, clock in. If this is first time "clocking in", wp creates two databases, one for "joe_smith" that would record a timestamp of when he hit the button and also the location he was at when he hit it. The other database would be named after the location and would record the date and time and who the user was who was at the location. After that, if Joe came back later in the day and was at the same location and selected the same properties, it would add another row of in "joe_smith" database and another row in "a_location"s row as well. If he changed locations it would still add to "joe_smith"s database but would create/append to the new locations databse "new_location".
Ideally I'd like to have the locations in a dropdown menu and that is populated by another db that houses all the location information and is editable by the admin. Am I on the right track with my thinking about how to set this up best? Anyone have any pointers or the ability to spit this code out easily? Haha. I've been doing my best at learning the wp system and how to create plugins and my deadline is coming up quickly to have something that functions. Thank you in advance to anyone that can help me on this :)
I would suggest that you split up the logic for creating the database and whatever needs to happen when the user clicks the button. In particular:
create a table when the plugin is activated (use register_activation_hook). More information about standard practices for this.
make your plugin store the available locations in WordPress' options table (use its API for managing it and create an appropriate options page for your plugin to manage them).
when the plugin is uninstalled (not deactivated), drop the table to leave everything as it was (using register_uninstall_hook).
when the user clicks the button, add an entry to your table (that will obviously need to - at least - contain a timestamp, the userid and the location).
Related
I am creating a site and i am making a general option page for the site that include the site name, logo, social links so that i can manage them dynamically from one place without changing the links and text in all pages where i called them.
What I want is that the table i created in database, i want to have only one row in it. If someone try to add other row of data it should not be added because i have to call only one data for the site.
I hope the query is clear to all.
Thanks for your support. Help me if u can. please :)
By,
if someone try to add other row of data it should not be added
what do you mean? Are you trying to avoid unauthorized access? If yes, then you need to implement roles https://laracasts.com/discuss/channels/general-discussion/roles-and-permissions-in-laravel-5
To manage your site information, I'm sure you set a form that will be used to update the site info. And from the look of things you will only be updating that row when you hit save or update button. I don't think you will be doing full CRUD here just updating so there'll be no chance of inserting a new row of data in the db.
So three things:
you want to create a migration, seed the table with the site details accordingly. run the migration
you want to make sure the user trying to access this route is authorized to do so
you want to pre populate the site info in the form fields when the edit site info page loads and you want to save the form when the authorized user changes any of the site info
This way, there'll be no question of stopping further insertions into the db.
The title may be a bit awful as I'm really not sure how to describe what I'm trying to achieve without using lots of words.
I'm currently building an events website. This website has the option for users to create their own events which can be added to a big list of upcoming events that other users have submitted.
What I want to do is be able to have a user create an event and have the details of the event stored in an SQL database (which I've successfully done), I want to be able to then have a large list of events on a separate page the details of which are pulled from the server dynamically using PHP and SQL (I've also successfully done this). The part I am struggling with however is being able to create unique pages (or a single dynamic page) that displays a more detailed look at the event, such as age restrictions etc etc, which cannot be displayed on the big list which displays all the available events.
I figured that this could be done using a unique eventID, which is something the SQL database already includes and autoincrements with each new event entry. What I'm really not sure about is how I'd be able to pass that eventID through the link to the more detailed page so that the detailed page can be created displaying all of the details of the event.
I'm not even sure if this idea will work at all. Would having a page with a unique URL that is created on event submission that has a more in-depth look at the details of the event be a better idea? How would I go about creating unique URL webpages that correspond to each event on event submission?
I'm really not sure how I need to go about this at all, so I need some help and pointing in the right direction.
Here's a kind of TLDR:
1) Events website
2) All events on the website are displayed on a single page that has minimal detail about each event (title, date, location) BUT has a link to a page that displays the event in more detail.
3) User can select an event from the list and click on that event's unique HTML link to more detailed page
4) More detailed page displays event in more detail by pulling event's unique information from the database
Feel free to ask any questions at all as I know this probably isn't the easiest idea to get across
When creating the links from the general listing page to the detail page, simply include the id in the link. For example:
<A HREF="mysite.com/detail.php?id=3>Big Event</A>
In detail.php then, you'll find the id in $_GET['id'].
I'm using chronoforms 5, made a form for creating a record. It works all fine.
But my problem is I need a form for edit the record. I've no idea how to load & show the record data. Anyone has ideas?
You have to be able to identify the record you want to edit. Usually this is by the Record ID, the User ID, or possibly the User email if that is unique. Then you can make a copy of your entry form, rename it, and add a DB Read action at the top of the On Load event in the Setup tab - if you are using the Simple Wizard then you have to switch the form to Advanced mode in the General tab to do this.
Edit the DB Read action to link to the table and set the Conditions box to load the record you want to edit - there is a FAQ about doing that.
You should be using ChronoConnection to list the records. The user selects a record which then displays the form to edit it.
I'm new to web development and I've been studying cakephp and I have this situation where I want to know the best practice.
Imagine a user creating a new Customer in the application, in the form he has to choose the customer's sales group, and this table has so many records, that's using a drop down list isn't a viable option.
I was thinking in the user press a button, then open a modal window. This new window would have a grid, with search options (for filtering the data) and the user would choose one, and go back to the original form, bringing back the sales group selected by the user.
What's the name of this technique, and is it a good option? How to do this in cakephp?
Best regards
Your question is about the front-end, so it doesn't matter if you are using CakePHP or another PHP framework.
What you want to do is make an ajax call to the server on opening the modal window, so it populates its' contents with your grid. Then, proceed as planned.
On the other hand, you can use something like Select2. This way you can have searchable drop-down menu right in your page and the user won't need to open a modal window. It's just more convenient for the user.
You can check the examples for Select2 here.
I'm currently developing a database/website server interface to facilitate inputting data for a data collection project. There are two types of additions being made to the database: A and B here. Some of the tables in the database that handle these entries are as follows:
dcs_projectname_a
dcs_projectname_b
Each of these have tables for all the required input fields in addition to things like creator, timestamp, etc.
The pages on the website facilitate three different options: add, view, and edit. Each page for each type of entry performs the respective function. That is, the add page adds, view page views, etc.
I am just about done; however, there is a major challenge I haven't really confronted yet: concurrency. There will be multiple users adding content to the database at the same time. Each entry is given its own specific id and there CANNOT be any duplicate id's. That is, the first a entry is A000001, the next is A000002, and so on.
On the add and edit pages, there is a disabled field for the user to view the id for other uses when physically documenting entries.
What I need to figure out is how to implement concurrency management so that when users are concurrently adding a's that they will not be under the same id and row.
The add page automatically generates the id to be used by accessing the database's most recent id and adding one.
My thought was to create a new row in the table every time the add page is opened and give it the calculated id. Then, when information is added it performs a modification to that existing row. This way, if another user opens the add page while another entry is currently being added it will be given the future id, not the same one.
With this method I need a way to delete this entry if the user leaves the add page or closes the browser. Then, I also need other users with open add pages to automatically update their id's to one less when the first user (or any other user less than the most id being used) leaves their add page and cancels the addition.
This is kind of a complicated explanation and if you don't understand let me know and I'll try to answer as best as I can. Any help is much appreciated!
Thanks
There's a number of solutions to your problem, but you seem to have made things harder by having your application generate the record IDs for you.
Instead, you could just be using MySQL's AUTO_INCREMENT functionality to automatically generate/increment the record ID for you (upon insert). MySQL will ensure that there are no duplicates, and you can get rid of the extra database call to retrieve the most recent ID.