I'm attempting to make a ticket system for out smaller company. I've made a submission form that saves to a mySQL database. I can save the data into the table and pull the date into a html table. I've been searching all day, however, to figure out how to put in a cell that will allow me to click a button, link, or whatever to change that row to completed. I have a field in the database for it, but I don't know how to get that cell into the table or how to get the link to understand which row I'm talking about. I've been searching Google for awhile and only getting how to make a html table with mySQL data or how to INSERT into a mySQL table.
You'll need 3 things: an UPDATE statement, the field in the row you want to update, and some unique way of identifying which row (entry) you want to update.
You'll probably want to create a link something similar to:
<a href='/path/to/update.php?id=myUniqueIdentifier'>complete</a>
and on the php page you'll want to use the $_GET['id'] passed (make sure to use msyql_real_escape_string()) to UPDATE your row and set your completed flag to whatever you want.
Lynda.com has a solid MySQL essentials video that has something very similar to what you are looking for. It would definitely be a good starting point for building your own custom solution. Or I'm sure you could just use their user interface to interact with mysql inside the browser.
I have no affiliation with Lynda.com - I just used their site to learn almost everything i know about programming.
Related
Been googling and trying all kinds of things but still can't figure it out.
Suppose i have a html form which has a table with lines (and input fields) in it. The lines have been populated by database (mysql) data. It is a journal with journal lines.
When the user changes one or more values of certain table rows and afterwards presses the save button, i want to only change the affected rows in the database.
Have been using delete * from table for a while now and then re-inserting all table rows. Crude, but for now it works. (but the autoincrement ID goes up fast and dependant rows in other tables sometimes raise problems)
The whole problem is that i dislike the idea of sending the record's ID to the client and sending it back when the save button has been pressed. Amongst other thoughts, i don't think an internal SQL ID belongs in the client.
There's got to be another way and someone else must've done this before, right?
Sure you can do things like keeping track of changes in the client, using UUIDs (insert them in the table and send that as the temp ID in the client) or keep a line number both in the client and in the table. But it takes a lot of work and feels either slow(er) or cumbersome.
And sure it gets even worse when you let the user add or delete rows to the html table and process changes those in the database
Does anyone have any pointers for me? I would be most grateful.
The way I would do this is add a CLIENT_ID column (or something like that) to my schema which would be a generated uuid and send that to the client along with the rest of the data and then send it back when the user hits Save. That way you don't have to expose the internal SQL ID, but you still have a way to identify certain entries in your DB. I'm not sure you can do this without sending some sort of ID to the client and then back to the server and even if you can, would it be worth the effort?
I was looking into using a database to store a generated link to that database entry that holds more information about the database entry. So you would see a bit of the database, then click on the entry and open a new page that holds more information about that entry.
What I was looking for was something to keep track of the amount of entries that have been entered, even if one of the entries have been removed. I know SQlite3 has count, but I haven't seen anything that would keep track of this. I was thinking in order reach my goal I would have to just set a counter and write it to a file and pull that counter when I am making a new entry, just wondering if anyone know something else I can do instead of reading/writing a file for one number.
Should be noted this is on a server that can be shutdown and restarted, the user must enter in the information that goes into the database and the server will log it for the user. And I don't want to every repeat the same entry number.
I have mainly used PHP, HTML, and Python for the current project I am working on.
I looked into this out of curiosity because you can do 'post save' and 'pre save' in most ORM-based webapps.
"A trigger may be specified to fire whenever a DELETE, INSERT, or UPDATE of a particular database table occurs"
https://sqlite.org/lang_createtrigger.html
CREATE TRIGGER aft_insert AFTER INSERT ON emp_details
BEGIN
INSERT INTO emp_log(emp_id,salary,edittime)
VALUES(NEW.employee_id,NEW.salary,current_date);
END;
It seems like the answer I was looking for was built into SQLite3, which is the best kind of answer.Auto Increment in SQlite3 allows for me to do what I was looking for. It will keep track of the amount of entries that have been added meaning I will be able to generate a link from the ROWID that I set to Auto Increment and not have a chance to repeat that it again.
I am working on a database in mysql and I need to make a user facing page that allows me to enter text for each field and then submit the record. I have been able to accomplish this easily, however it is getting quit annoying having to update the input.html and save.php every time I decide to add/remove a field.
It really seems like there should be some sort of program that can auto-maintain the code for me and allow me to just focus on the database structure. Does anyone know of something that does this? I feel like I am doing it all wrong.
Thanks in advance.
P.S. I realize that I could just use phpmyadmin, but I do not want to give full DB access to my data entry people; plus they are not technical types, I don't want to intimidate them.
In the end, I decided to make my own script, using INFORMATION_SCHEMA to get the field names, and then made a recursive loop to add each record. It wasn't hard, but it seems like there should still be a better way.
I need to have a button to fire an action to copy all records from a defined client from one database to another with php.
The template database has 12 tables (diferent rows on each) but all with the row client_id to make the WHERE clausule work properly.
The question is, how do I do this?
Thanks,
Pluda
Since PHP is a Server-side programming language, you can't copy something from the client. You can however upload Data (like XML), parse it and then insert it into your MySQL Database.
If you want to copy records from one to another database, you might want to read from the Database and save them in a format like SQL. Then, you could send those querys to the second Database.
An advise at this point: If you need to make the same Query (with different values) over and over again, you should use a PreparedStatement. It will be compiled in the Database and then just filled out with new values. This is way faster then using an Insert every time.
Google unfortunately didn't seem to have the answers I wanted. I currently own a small search engine website for specific content using PHP GET.
I want to add a latest searches page, meaning to have each search recorded, saved, and then displayed on another page, with the "most searched" at the top, or even the "latest search" at the top.
In short: Store my latest searches in a MySQL database (or anything that'll work), and display them on a page afterwards.
I'm guessing this would best be accomplished with MySQL, and then I'd like to output it in to PHP.
Any help is greatly appreciated.
Recent searches could be abused easily. All I have to do is to go onto your site and search for "your site sucks" or worse and they've essentially defaced your site. I'd really think about adding that feature.
In terms of building the most popular searches and scaling it nicely I'd recommend:
Log queries somewhere. Could be a MySQL db table but a logfile would be more sensible as it's a log.
Run a script/job periodically to extract/group data from the log
Have that periodic script job populate some table with the most popular searches
I like this approach because:
A backend script does all of the hard work - there's no GROUP BY, etc made by user requests
You can introduce filtering or any other logic to the backend script and it doesn't effect user requests
You don't ever need to put big volumes of data into the database
Create a database, create a table (for example recent_searches) and fields such as query (the query searched) and timestamp (unix timestamp that the query was made) said, then for your script your MySQL query will be something like:
SELECT * FROM `recent_searches` ORDER BY `timestamp` DESC LIMIT 0, 5
This should return the 5 most recent searches, with the most recent one appearing first.
Create table (something named like latest_searches) with fields query, searched_count, results_count.
Then after each search (if results_count>0), check, if this search query exists in that table. And update or insert new line into table.
And on some page you can just use data from this table.
It's pretty simple.
Ok, your question is not yet clear. But I'm guessing that you mean you want to READ the latest results first.
To achieve this, follow these steps:
When storing the results use an extra field to hold DATETIME. So your insert query will look like this:
Insert into Table (SearchItem, When) Values ($strSearchItem, Now() )
When retrieving, make sure you include an order by like this:
Select * from Table Order by When Desc
I hope this is what you meant to do :)
You simply store the link and name of the link/search in MySQL and then add a timestamp to record what time sb searched for them. Then you pull them out of the DB ordered by the timestamp and display them on the website with PHP.
Create a table with three rows: search link timestamp.
Then write a PHP script to insert rows when needed (this is done when the user actually searches)
Your main page where you want stuff to be displayed simply gets the data back out and puts them into a link container $nameOfWebsite
It's probably best to use a for/while loop to do step 3
You could additionally add sth like a counter to know what searches are the most popular / this would be another field in MySQL and you just keep updating it (increasing it by one, but limited to the IP)