Creating a GUI (PHP/MYSQL) - php

I need some consultation here. I am a C# developer, and for just about all of my applications, I enjoy building the GUI up before writing most of the code (it's just how my brain functions).I am very new to PHP/MYSQL, and I am having a LOT of trouble wrapping my head around the right way of doing what it is I am trying to do (see below). Please keep in mind I am only looking for graphical help here - what would you do to make this look sleek?
I have a database which will hold a decent amount of customers. For example purposes, let's say this database will hold 50 customers. The table which holds all customer information is 5 columns across, and, in this case, 50 rows down. I need to have the ability to add new customers along with the ability to delete old customers from the database. (* AGAIN * I am not looking for code here, but advice on how to go about designing this page). For adding new customers, I have a seperate .php page with an html form, and five textboxes. This will create a new row. Deleting / editing customer information is what I have yet to come up with. I can't decide if these functions should be placed onto a separate page or the same one as the database.
Basically, any ideas / help at all will be much appreciated.

I'd probably display the information in a table, add a delete control column at the end of each row, and some kind of edit in place option. Either turn the row into editable inputs, or slide down an edit row right beneath the row in question when a user wants to edit a record.

If you have just five fields I would do all remove-update-delete operations on the same page, and creating records in a seperate for like have now.
Basically each row could have controls edit/delete control at its right, pagination controls could be a bonus for 50 rows and more. But .. hey, have you not seen any similar layout before? I seem to be explaining what is the most basic gui layout of most any record based web application.

You could mock the page up using good old fashioned pen and paper, i do this sometimes when theres a lot going on on a page. I find it helps me quite a bit.

Related

Automated Process to Add New Data to Table

I am working on a website which utilizes a table for presenting old and newly passed laws. As such it requires that we have a large volume of data in the tables, and we constantly have to add more data to the tables.
I know already how to construct the table through CSS and HTML; however, due to the sheer volume of data which we are dealing with, I would like to know if there is a way to create a separate admin page where we can just plug in the law information and have it automatically added to the table rather than having to physically code in all of the information through HTML.
I also have a second question: I would like to add some tabs at the top of the table which allows users to sort laws based on the year they were passed. An example of this can be seen at this site: CT Legislation | 2014 | General Assembly | Passed | LegiScan . It has several tabs at the top which allow users to sort legislation- my question is what coding language is required to add this to a table?
A CMS may or may not do it for you. What really would be good is to use Parse to hold all your data. Take a look at Data Storage and Cloud Code. You can add new laws whenever you want, and you would configure Parse to dynamically add the data to your table for you.
You can use a variety of languages for this type of solution. If it were all web based it would likely utilize php for building a password protected page (admin) page. It would also be used along with SQL to send/receive data from the Database, the it could use CSS/html for the table and content styling.
For the database you could use MYSQL (a type of database).
If this is beyond what you are comfortable with, a content management system (CMS) would be a great option. They set up the entire backend for the user and have an interface that will allow someone who knows zero code or html/CSS to put a pretty decent website together.
The great part about using wordpress is it lends itself well to someone looking to learn more about development. You can see how things can be set up with code to achieve certain outcomes and can learn more and more as you work with the system on increasingly deeper levels.
Another option is using google drive. There are tabs, a table and it is cloud based so you can share it with people you want to have access to it. Anyone you choose can add/delete and it keeps very good track of what is changed and who made the changes. It is really easy to go back an fix things if they have been messed up.

Do I need to create a new database for copies of the same form?

Here goes a very basic question.
Here is my stroll in trying to create a form for work:
I created the HTML form. Added some JavaScript to make it do some things I needed. Stylized it with CSS, wrote PHP code and created a Database (I had no idea of how to do it at first) for the entered data to be saved.
I didn't know how to do any of that, but in the past two weeks I've managed to make it exactly the way I needed, and I'm very pleased with myself. After a lot of work, the form perfectly sends the data to the database and displays it in the page after you hit submit, and also looks really good too.
The thing is... this that I am creating is an Activities Bank for us to use here at work (I teach English) and the page (base) I have created is only ONE of MANY that are needed in this data bank. Let me explain... Let's say the page I've created is the post and display of, say, Book3 Chapter1 Activities, and I need to have many other pages (which will be exact copies of this one).
My question is... will I have to create (actually, it's copy and paste) new databases/tables manually (which will be more than one hundred of them) or there is a way to automatize this process?
I mean, all the pages will share the same variables and the same form... the only different thing will be the title and the entered data, of course.
Will I have to create a database for each page? Or a new table for each page in the same database?
If you still don't understand what I need, here is how this is supposed to be:
Book1 has 40 chapters, so, 40 copies of the same form (which already works fine);
PLUS
Book2 that has 40 more chapters, etc.
Thanks in advance for any clarification.
Sorry if this is such a basic question, but if it isn't, if otherwise, what I wanna do is very complicated, I don't mind that I don't know much about all this and I will take the challenge, like I have, when I was making this form from scratch, without ever hearing about "databases". Any words of help are appreciated.
That isn't how databases or tables work. You should be creating a new row in one or more tables for each form submission. You should almost never be dynamically creating tables, and even less often databases.
It sounds like you want a books table, and a chapters table. Each row in the books table will have many rows in the chapters table "pointing" to it via foreign keys.
I think in your case your case two tables.in total.
As you have already added one, you need another one, where the first one will contain the common data with a primary key column and the other table will keep the primary key of the first table and the data which occurs in multiple. Then later you needs to join (Sql join)rotatable to get your data.

PHP + MySQL cascading searches from linked query results

Apologies in advance for the wall of text; not sure if this is possible but i thought i'd ask. I've looked online and can't quite find what i want. I have been learning a lot of PHP and MySQL and am at the stage where i am starting to write my own database driven websites. A freely available database i have been practicing with is the eve_sdd_crucible_11 database which is freely available from the game website. I have been using it because it's huge and requires the use of a lot of different skills to get the most out of it.
I would like to do a simple database for exploration. This database queries the main one for information, creates a new table based on the search results and also allows the user to add their own comments on what they have found. I have the various queries ready to go but because i don't want a massive user interface, i want to keep the user side as clean as possible. This app needs to query and display results from the 'mapregions', 'mapconstellations', 'mapsolarsystems' and 'mapdenormalize' tables and insert this information into a new database with the retrieved info plus a comment box for each entity.
Now the preamble is done, this is what i am looking to do:
Query 'mapregions' (region name returns region ID to be used in next query) and display results (linked)->
click on linked result, query 'mapconstellations' (constellation name returns constellation ID to be used in next query) and display results (linked)->
click on linked result, query 'mapsolarsystems' (solar system name returns solar system ID to be used in next query) and display results (linked) ->
click on linked result, query 'mapdenormalise' and display all entities in that system -> Inject content into new database along with comment boxes per listed entity.
Like i said earlier in the post, i have the queries set up ready to go, i have the beginnings of the php for the page but i am stuck on how to link these displayed results to the next query in the chain. All results have to display the name of the entity and it's the entity's corresponding ID number that is used to execute the next query in the chain.
Not sure if i've explained it particularly well, but it's the best i can do at this time of night... Any help or pointers would be vastly appreciated as it's starting to do my head in ;)
Need to look into joins - from reading through that text, it seems like you're missing a basic understanding of how to join tables - your 4th paragraph, to me, sounds like it should be a single query.
Creating a new database and/or table per search shows that you might still be missing some of the fundamentals - as that approach would never scale and would be a nightmare to manage.
Start reading up on mysql joins: Mysql Joins and go from there, looking at other examples of how joins work and real world examples - that will hugely affect how you continue building this.

Tracking data changes

I work on a market research database centric website, developed in PHP and MySQL.
It consists of two big parts – one in which users insert and update own data (let say one table T with an user_id field) and another in which an website administrator can insert new or update existing records (same table).
Obviously, in some cases end users will have their data overridden by the administrator while in other cases, administrator entered data is updated by end users (it is fine both ways).
The requirement is to highlight the view/edit forms with (let’s say) blue if end user was the last to update a certain field or red if the administrator is to “blame”.
I am looking into an efficient and consistent method to implement this.
So far, I have the following options:
For each record in table T, add another one ( char(1) ) in which write ‘U’ if end user inserted/updated the field or ‘A’ if the administrator did so. When the view/edit form is rendered, use this information to highlight each field accordingly.
Create a new table H storing an edit history containing something like user_id, field_name, last_update_user_id. Keep table H up-to-date when fields are updated in main table T. When the view/edit form is rendered, use this information to highlight each form field accordingly.
What are the pros/cons of these options; can you suggest others?
I suppose it just depends how forward-looking you want to be.
Your first approach has the advantage of being very simple to implement, is very straightforward to update and utilize, and also will only increase your storage requirements very slightly, but it's also the extreme minimum in terms of the amount of information you're storing.
If you go with the second approach and store a more complete history, if you need to add an "edit history" in the future, you'll already have things set up for that, and a lot of data waiting around. But if you end up never needing this data, it's a bit of a waste.
Or if you want the best of both worlds, you could combine them. Keep a full edit history but also update the single-character flag in the main record. That way you don't have to do any processing of the history to find the most recent edit, just look at the flag. But if you ever do need the full history, it's available.
Personally, I prefer keeping more information than I think I'll need at the time. Storage space is very cheap, and you never know when it's going to come in handy. I'd probably go even further than what you proposed, and also make it so the edit history keeps track of what they changed, and the before/after values. That can be very handy for debugging, and could be useful in the future depending on the project's exact needs.
Yes, implement an audit table that holds copies of the historical data, by/from whom &c. I work on a system currently that keeps it simple and writes the value changes as simple name-value string pairs along with date and by whom. It requires mandatory master record adjustment, but works well for tracking. You could implement this easily with a trigger.
The best way to audit data changes is through a trigger on the database table. In your case you may want to just update the last person to make the change. Or you may want a full auditing solution where you store the previous values making it easy to restore them if they were made in error. But the key to this is to do this on the database and not through the application. Database changes are often made through sources other than the application and you will want to know if this happened as well. Suppose someone hacked into the database and updated the data, wouldn't you like to be able to find the old data easily or know who did it even if he or she did it through a query window and not through the application? You might also need to know if the data was changed through a data import if you ever have to get large amounts of data at one time.

Forum achievements on a phpBB3 board?

I recently started a new community. The forum software is phpBB3, and so far so good. In an attempt to make my community more unique and interesting, I had to idea of having user achievements. Let me give you a quick run-down.
Each user has achievements that they can earn (these will probably be across all users), for example an achievement for when a user hits 1,000 posts, when they upload an avatar, when one of their topics gets 1,000 views and so on. Each achievement has points, for example an achievement like uploading an avatar will be 10 points and reaching 10,000 points will grant 50 achievement points. If anyone here plays World of Warcraft you may be seeing where I'm getting the ideas from. :)
What I'm struggling to get my head around though is how exactly to code this... I could keep a record of all users activity and add it to a special database table possibly, and then check via cron every minute or so if any user has met achievement criteria... but then I also want it controllable through the ACP so I can easily add new achievements and change their points etc. My mind is pretty blank when it comes to anything but the most simple things.
What I really posted here for was feedback on the idea and how you all think I should go about doing this. The coding part should be pretty simple for me once I get my head around how phpBBB MODs need to be written.
Thanks for reading, and I look forward to your replies. :)
Have you checked out this mod?
http://www.phpbb.com/community/viewtopic.php?f=70&t=1696785
It's in beta at the moment but it looks like it's sorta what you're trying to accomplish. Even if it isn't, you can always take it and make something else out of it. I have heavily modified existing mods to suite my site. It takes a little while to get your head around how things are done with phpbb3 but it is easy when you start doing it.
In regards to creating your own, I don't think this has to be done on crontab. You could simply inject a function into the relevant parts of code.
With post counts, there is already a function that updates the description under the avatar of users based on certain post numbers, you could probably put an extra function update_achievement() there. Same goes with the avatar being updated. Unfortunately, taking this approach you will not be able to edit the achievements completely from the ACP but you could possibly have an interface that could enable/disable certain achievements.
You will obviously need an extra table or two for this. Without thinking too much, I would have 1 table that has 2 columns, user and acheivement_id. Then another table which just lists the acheivements ids and descriptions etc..

Categories