Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a very simple site (PHP) that allows user changes (via jQuery) that modify elements' classes, and add/delete rows from a table.
I want to write these changes to the actual PHP file in question on the server every time a user makes a change, so that when the page is refreshed or revisited, the changes remain intact.
What's the simplest / best way to accomplish this? Thank you!
For addition/deletion of rows, fire ajax call and update records associated with the user. This is in addition to client-side (jQuery/JavaScript) changes to page. Whenever they revisit/refresh the page, data will be fetched from db, and as such will always be latest.
When you say that users modify elements' classes, I assume you mean their page's looks and styling (like some sites have on-page options to change background color, font-sizes). If that is the case, I suggest you:
Create a list of all possible states and store them in a new table in db, say display_options. You could store details like option_type (e.g. background color, font-size etc) and option_back_value (e.g. #FFF, #000 etc).
Create a new table say user_display_options where you store things like user_id, option_type and their chosen option_id.
While loading page, do a join on these tables using user_id. Then while creating your page, conditionally add classes etc to the page.
When user edits page, fire ajax call sending required data like user_id, option_type, option_id. As mentioned for other task, these changes to db will be in addition to client-side changes.
Also read #David 's comment to your question - it clears an important concept.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm doing a web app with PHP in which users have different number of tabs in the menu depending on a certain number of things, one user can have one tab in the menu where another user has ten.
I've managed to dynamically generate the menu items but now I don't know how to create files (pages) where the user gets redirected once he presses on any of the menu tabs.
All these files look the same the only thing that changes are the text, just some strings.
Summing up, what I want to do is:
Generate and destroy files automatically when the user has to consult something
How to link the menu tabs (href) to them automatically
The best would be to use a PHP page as template you could call it.
Lets say for example a user is logged in and clicks the view data page (data.php)
on your link you could have something like this:
and in data.php:
<?php
$USER_ID = htmlspecialchars($_GET["id"])
//SQL Request to get user priviledge and authentificate
//OR
//Check the cookie session for information
if (user_priviledge == 0)
{
//
//Show only data for 0 users
//
}elseif (user_priviledge == 1) {
//
//Show only data for 1 users
//
}
?>
This may not be the solution you wanted but your question wasn't very clear either so if you need any other information make sure to bring more precision.
The condition which are using for tab use same condition to show page. But add that condition in your text.Because your text is changing not page I think.
I this this might help you.
since all files will look the same and only variables will change, you can create one php file and just send the necessary data when a user clicks on the tab to assign to the variables in that page. You do not need to keep on creating custom pages for each and every tab.
Provide some code which you have written for this so that we can help you further
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have to tables: Messages and Favorites and a Dashboard list to feed.
Messages table is structured like this:
from_user_id | to_user_id | message | timestamp
The Favorites table is structured like this:
user_id | fav_user_id | timestamp
The dashboard list has to be fed like this:
if dashboard owner (that is loggedin user) exchanged messages or has favorited another user, this user must be added to the dashboard list.
My question is: is it better to populate the dashboard by reading the two tables when dashboard needs to be loaded or creating another table called "dashboard" which summarizes the other two tables content and eventually reading dashboard list only from it?
Note: the dashboard table is populated like this: when a new row is added to tables Messages or Favorites a check is done on the Dashboard table to see if it has to be updated.
It sounds like your dashboard is acting like a cache for the data in messages and favorites.
When you think about it this way, you are asking:
Is it better to derive and cache statistics or read directly from 2 tables?
There is no correct answer. But, understand that applying caching this way my be a case of premature optimization, which you can Google for.
Adding a layer of calculation between your source data and your display data simply adds one more place where things can:
be stale
be calculated incorrectly
have stale definitions
If you want to change the row definition of messages or favorites, you might also need to change the definition of dashboard to hold the new information, you would also have to update the trigger/event/callback that updates dashboard when new data is inserted. This may not sound like a big deal, but when someone says "The data on this page is wrong" you will start debugging by looking at the code that makes that page, not a hidden callback/listener triggered when data on another page is updated.
IMO, simplicity trumps cleverness everytime.
I would keep it as two tables. Adding the two together means that you repeat data when you don't need to. Something like from_user_id | to_user_id | message | timestamp| is_fav | fav_timestamp would be needed and the last two columns would just be the same data for every message, unless you are looking to track changes in that status over time.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to recreate something you might know from imgur or jsfiddle - you just type something or upload images, then you click "save" or "upload" and then you get a original link in form of imgur.com/smth or jsfiddle.net/smth. How is this done? I've created simple website where I can write notes and save them and it works perfectly well for myself, but I wanted to share it with some of my friends and I have absolutely no idea how can the "save" button attach their changes to new URL every time they press it? I know this is pretty basic but I couldn't find anything on the matter online and I really have no idea how to handle this issue, excepting I'll be writing their changes to different SQL rows.
Thanks for any clues :)
If you're trying to create something and let people edit it and keep the same link you could do it with PHP and mySQL.
I think the easiest way would be to have one page to create the initial note and one to update/view it. Once you create it the save button would add it to a database with a unique id of some kind like an auto increment number. To send the page you would use a link like www.somepage.com/info.php?id=1. The "id=1" part would be the unique id within the database. In info.php, you would need to use $get_["id"] and set that to equal the database id row and load the info from there. Then you could allow edits to that row from that page. You would have to set the save button to update the row.
To get something like somepage.com/smith, if you're on a linux server, you would use htaccess and mod_rewrite.
This is a really down and dirty gist of how you could do this, but it should send you in the right direction.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a simple page that shows 4 different divs, all with a <h1> title (or other tag that shows text) and a form (with 1 input text) and a submit button... so far so good.
My answer is simple: I am looking for a way that:
when the user inserts a text and submit the form, the <h1> title shows the text that the user wrote
the form disappear (or takes style display:none)
this will take effect even if I refresh the page or view page in a different computer (probably need to save the data in a DB)
restart this process from the beginning (even if I need to code again).
This is for a mini game to provide to users 4 different choices and, if the user A select option 1, the <h1> will show text something like "User A was the first to choose this option. Please select a blank option" and, after the 1st raw over (point 4 described above), restart all forms.
NOTE: I am not asking in the way to "please do the code for me". I also searching for a way to store data in <php ?> - finding redbeanphp project.
I am also a newbie in SQL (just started to study SQLi last month to android development). My question is ONLY to looking for the best way to do this and what I need.
This would be the workflow:
When you click a button to submit the form JavaScript will send the form data to the server as an AJAX request and wait for a response from the server.
The PHP code on the server will read the data from the AJAX request and save it in a database and echo a success response along with the text to display.
Your JavaScript will receive this success message and hide form from the DOM and display the text in the header.
If you want the data to persist on the page on reload then you can save a flag in PHP session. Sessions persist in until you close browser window.
4.1 Use another AJAX call remove the flag from the session and reload the content.
So, if you are good with HTML and CSS you need:
JavaScript, AJAX, a JavaScript library to make things easier such as JQuery.
A server side language such as PHP.
A database to persist data. There are many choices. I am going to recommend MySQL just because there so many tutorials for it out there.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
I doubt I'm using the correct vocabulary (or tags) to explain what I'm looking for, but bear with me:
Eventually part of my page will have a section where things like list items and table data(<td>) can be entered/changed by logged in users. Let's say this is one of the <li>'s:
<!--template-->
<li><a title=""href=""><span></span></a></li>
So far my understanding is that if these entries are generated by a UI somewhere (à la Wordpress) these entries need(?) to be written in a database before becoming the generated page. Another thing I'm realizing is that the user of these CMS's doesn't automatically 'get' a copy of the generated page as source code.
What I would like to know is if it would be possible for me to make changes in HTML to this generated record/list inside notepad (I'll likely be messing with some other part of the page) and somehow have the site detect/record any changes as if they were entered through the UI?
Have PHP code create a file of the generated page
Have that page scanned for certain patterns/templates
Add the values found within the template to the DB, repeat
What language/approach could scan text and make database entries from its findings like how I'm describing? I just discovered sscanf(), but have no idea how to use it yet. I realize it's stupid to not just use the CMS, but the self-referential and text-scanning quality of it also interests me.
It sounds to me like you can implement a jQuery "Edit in Place" plug-in with a php script handler. I did something exactly this and their plug-in does all the heavy lifting, all you have to do is feed out the raw HTML with various clues about the table structure.
See this SO q/a... I used it to generate pages that displayed orders. Via editing in place, I made the orders (click-to-edit)-able. In the code, put everything in a foreach loop, then the jQuery links elements to the database through attributes like <tr id="<? echo $database_ID ?>"> to tie a row to a record and each <td> might have the database's column name as ID or a class name.
Let me preface this answer by saying it's almost certainly a bad idea, only tangentially relates to PHP, and creates at least as many problems as it solves. In particular, the security loopholes are terrible. But recently I saw an HTML form on a government website that reinvigorated my sense of humour about "lateral thinking", so just call me Pandora.
Theoretically you could implement something like this with a bit of Javascript and a cross-domain <form> post. In a nutshell, you would:
Create an HTML template with all of the tables, lists and other structures you require, plus a <form> containing a hidden input and a submit button. This template would be populated with data by the server application when the user initially requests a particular record.
Create a script for the template that parses the tables and lists for values (say, with DOM methods), serializes them (eg, into a JSON string), and sets the value of the form's hidden input to the serialized data.
Set the form's action attribute to a PHP script designed to deserialize the form data and persist it to a database. Also assign an event handler on the submit button that executes the serializer script before the form is posted.
Now, the trick here is in the user sequence. The user requests some record, which the server returns in a populated template. Ordinarily, a user would work with whatever CMS-style fields the template provides, but expiredninja instead saves the HTML source of the page, makes changes to the designated tables and lists, opens the modified HTML file in a browser, and clicks submit. The script serializes the data and the client posts the form to the server, which deserializes and saves the data.