In an attempt to redesign a website, I put this page together by hand. However, there are currently over 100 more shows already that need to be added, and three new shows get added every year.
In the old system, a text document was used as a makeshift 'database'; it stored data about each show, with shows separated by '#' and data fields separated with ']'. Here's an excerpt:
#The Whorl of the Leaves]WhorlOfTheLeaves]3]F]167
#Aladdin]Aladdin]8]N]0
#A Christmas Carol]XmasCarol84-]7]N]0
#The Feral Child]FeralChild]7]N]118
#Camelot]Camelot]11]N]169
A PHP script was then used to extract the information about each show and make the page seen here.
I'm sure a script could be used to put together a page such as the one shown above, but it seems like there should be a better system than a text document to store the information.
My question is: if the text document 'database' is working, should I bother changing it? Is there a better way to organize the information about each show?
SQLite would be prefect for you. It's a tiny database that requires no configuration or setup - yet comes built into most PHP installs.
Just use PDO and your good.
$db = new PDO('sqlite:/path/to/here/mydb.sq3');
$db->query('SELECT * FROM shows');
Yep, there are a ton of "better" ways of doing this. But if you're happy with it and it works, why change it?
You could save yourself a lot of trouble by using a content management system such as drupal.
Related
So, it's my first question here - i found a lot of hints which all working for itself but im struggling now with the final step to get solved.
Guess it's very specific pointed to TYPO3-CMS V9 and higher.
I can also support with all of the Codes, for the moment i guess this will be better on request.
Task: Create a simple Productorderform for logged-in-users pointing just there specific products form the specific price-lists. -> solved by using PHP-Script working with a CSV-File, grabbing also some functions from TYPO3 itself to get needed parameters.
This PHP creates a DATALIST on runtime for the INPUT-Field producing the needed HTML-Code -> solved and working as expected.
Tricky part.
As TYPO3 offers a CORE-Extension called FORM and the Option to - REPEAT - the fieldset.
Also for TYPO3 there is an extension which allows to put PHP-Code directly to TYPO3 as a Content-Element.
FORM itself allows to put Content-Element to a form.
Working so far, but as described, the field (its value) is not recognized when i fire the send button.
So for some reason i have to predefine the trigger also.
I tried step for step to extend the predefined field in the php with the tags of an empty one, all(?) the surrouding DIV etc. to make FORM recognize this field as a "native" field, just extend in the main tag with ... list="prodlist" ...
Well, as you might see, i'm not a developer or programmer, i might have some skills and experiences to know where and how to go with the level (and timeframe) i have.
So i guess the final step might not be that far, but as we say here, i can't see wood because of trees...
The FORM structure by the way is saved to a YAML-file which might be also manipulated, but as i have seen, it gets the triggers -what- to parse in some way from the FORM created.
Many thanks for hints, ideas an hopefully noone was falling to sleep reading this question... ;)
I am trying to make it so users can enter text files and a short message near it and it will be visible for everyone. I am using PHP and SQL (MariaDB/MySQL for the database) and I want it so every like ten for example inputs it will make a new page. So for example if there is ten files up on the page then if someone puts another one in it will automatically make a page two and have the oldest file submitted be there. How can I do this. I have seen other sites use a GET method and have it be something like ?page=2 . How can I do this myself?
What you're looking for is "Pagination".
Pagination using MySQL LIMIT, OFFSET
Though that can look a bit scary at first. However, if you use a framework such as Laravel it can easily be done, see:
https://laravel.com/docs/8.x/pagination#introduction
There are quite a few different threads about this similar topic, yet I have not been able to fully comprehend a solution to my problem.
What I'd like to do is quite simple, I have a flat-file db, with data stored like this -
$username:$worldLocation:$resources
The issue is I would like to have a submit data html page that would update this line based upon a search of the term using php
search db for - $worldLocation
if $worldLocation found
replace entire line with $username:$worldLocation:$updatedResources
I know there should be a fairly easy way to get this done but I am unable to figure it out at the moment, I will keep trying as this post is up but if you know a way that I could use I would greatly appreciate the help.
Thank you
I always loved c, and functions that came into php from c.
Check out fscanf and fprintf.
These will make your life easier while reading writing in a format. Like say:
$filehandle = fopen("file.txt", "c");
while($values = fscanf($filehandle, "%s\t%s\t%s\n")){
list($a, $b, $c) = $values;
// do something with a,b,c
}
Also, there is no performance workaround for avoiding reading the entire file into memory -> changing one line -> writing the entire file. You have to do it.
This is as efficient as you can get. Because you most probably using native c code since I read some where that php just wraps c's functions in these cases.
You like the hard way so be it....
Make each line the same length. Add space, tab, capital X etc to fill in the blanks
When you want to replace the line, find it and as each line is of a fixed length you can replace it.
For speed and less hassle use a database (even SQLLite)
If you're committed to the flat file, the simplest thing is iterating through each line, writing a new file & changing the one that matches.
Yeah, it sucks.
I'd strongly recommend switching over to a 'proper' database. If you're concerned about resources or the complexity of running a server, you can look into SQLite or Berkeley DB. Both of these use a database that is 'just a file', removing the issue of installing and maintaining a DB server, but still you the ability to quickly & easily search, replace and delete individual records. If you still need the flat file for some other reason, you can easily write some import/export routines.
Another interesting possibility, if you want to be creative, would be to look at your filesystem as a database. Give each user a directory. In each directory, have a file for locations. In each file, update the resources. This means that, to insert a row, you just write to a new file. To update a file, you just rewrite a single file. Deleting a user is just nuking a directory. Sure, there's a bit more overhead in slurping the whole thing into memory.
Other ways of solving the problem might be to make your flat-file write-only, since appending to the end of a file is a trivial operation. You then create a second file that lists "dead" line numbers that should be ignored when reading the flat file. Similarly, you could easily "X" out the existing lines (which, again, is far easier than trying to update lines in a file that might not be the same length) and append your new data to the end.
Those second two ideas aren't really meant to be practical solutions as much as they are to show you that there's always more than one way to solve a problem.
ok.... after a few hours work..this example woorked fine for me...
I intended to code an editing tool...and use it for password update..and it did the
trick!
Not only does this page send and email to user (sorry...address harcoded to avoid
posting aditional code) with new password...but it also edits entry for thew user
and re-writes all file info in new file...
when done, it obviously swaps filenames, storing old file as usuarios_old.txt.
grab the code here (sorry stackoverflow got VERY picky about code posting)
https://www.iot-argentina.xyz/edit_flat_databse.txt
Is that what you are location for :
update `field` from `table` set `field to replace` = '$username:$worldlocation:$updatesResources' where `field` = '$worldLocation';
I have an HTML table with contents, I would like to have an feature of Edit/Delete to that table. How do I do it with PHP?
I actually think that this sounds more like a job for JavaScript, which can edit/remove rows on-the-fly and with much less code. (Implement some AJAX too, and you can edit/remove rows in database too).
But if you insist on using PHP, you might just want to add some GET parameters to the Edit/Delete links that would delete or edit those rows.
Well, there is a pure PHP way to do it, and then there is a combination of Javascript and PHP. You must use PHP one way or another if you want your changes to the database to be permanent as that is your gateway to communicating with the database (as far as I know you cannot do that with Javascript as that is client-based and runs entirely in your web browser).
If using just PHP, you must generate HTML documents for each change. E.g., you click on one cell in the table and that gets you to a new HTML page where the field is editable through an input element; or you can list all fields at once for that row and edit them all at the same time. The fields are then posted in a form to a PHP page which will take the new values and update the database (or insert new values or however you wish it to behave). Here's a tutorial for how to do this:
http://www.freewebmasterhelp.com/tutorials/phpmysql/1
You can also mix in some Javascript which allows a more interactive interface to modifying the values in a cell. However, this obviously requires more code and may be overkill for what you're trying to do. Nonetheless, here is a link which demonstrates just that and also shows the code:
http://www.java2s.com/Code/JavaScript/GUI-Components/Editabletablecell.htm
Hope this is what you're looking for.
EDIT:
Forgot that you also wished to delete content in the table. That is also explained in the first link.
If you intend to work with databases, and it seems like you have little understanding of how they work, pick up a good book like: SQL - The Complete Reference. When you have enough knowledge of SQL, look at PHP's PDO extension: http://php.net/manual/en/book.pdo.php
I'm trying to think of a way to create a list of items that I can display on a webpage that my visitors can tick off, without ever having to log in.
The list may be like so:
[ ] Buy potatoes
[ ] Pickup kids
[x] Drink more water
[ ] Go for a Run
If User A visits the site, and clicks "Drink More Water" I want that to save in a database so that when User B visits, "Drink More Water" is already ticked.
Is there any simple ways to do that:
in PHP?
with Javascript?
or even as a WordPress plugin?
Do you know if there's any existing code around that does this?
TaDa List by 37Signals comes very close, but only allows specific people to tick things off.
Any suggestions would be greatly appreciated.
Thanks
Turgs
If you want to create this yourself you should learn PHP and MySQL (and possibly Javascript (for AJAX)), and HTML and CSS (maybe you already know some of these). After you know these it will become clear how to create this.
You should first learn HTML
then PHP
then MySQL (or any SQL that works with PHP)
then CSS
Then Javascript
We can't really answer your question like this, because it involves big amounts of code. Adn won't really help you if you don't know these languages.
I'll tell you what you need to do, but you're going to have to research most of the things.
You need html to create the list.
You need php to query sql and check if one of them should be checked or not.
Load the page with the data you got from your database server (set the checked ones as checked).
When the user checks one of them you need to store it in the database, so that when another user loads the page he can then get the changes from the database.
Hope this is clear enough.
Just store that information in cookies.
$_COOKIE['ticket'] = 3;
when he visit the page next time just check if $_COOKIE['ticket'] is not empty.
You could do this kind of thing with a file instead of a database. So when the user checks off a box, it loads a PHP file that reads an XML file with the tasks and check-status, then re-writes that file with the modified value.
It's quick, dirty, and doesn't need a database.
You could use a REST like url that defines a list. i.e.: http://ticklist.com/list/145
People can share this common list.
Something like the logic of http://friendpaste.comTo let people share and edit source codes.