the Poll system have two part(the user cast poll part and the result show part) the cast poll part has two buttons. which is up and down. the result show part using five star to show the average result which casted by all the vistors. say concisely: the poll system has two button, on is up, another is down. when a vistor polls up/down. it will show the average poll result of the article. which is displayed by five stars.
You need at least Javascript for that. To update the database dynamically when a button is pressed, you need some AJAX code.
Glance over http://jquery.com/ There are tons of examples, plugins, discussion there.
Related
I have a dropdown menu that has school subjects listed. I also have a countdown timer for each subjects test date (many subjects share a date). I want to make it so that when the user selects the subject, the right countdown timer appears without the page refreshing.
Right now I have this working using PHP: I have 9 different countdown timer made in JavaScript (I used this tutorial from w3schools) and 9 separate PHP files like this:
$newSubject = $_GET["chooseSubject"];
if ($newSubject == "Math" OR $newSubject == "Chemistry") {
echo '<p id="subjectSet1"></p>';
echo '<p class="dates">October 16. 2019 klo 9:00</p>';
}
I have a button that redirects to a page that then shows the correct countdown timer.
However, I'm looking to achieve something like this:
https://yle.fi/aihe/artikkeli/2019/05/15/ylioppilaskokeiden-pisterajat-kevat-2019
Under the "Ylioppilaskokeiden pisterajat, kevät 2019" there is a select menu, and when you choose a subject it automatically shows the correct table.
This is where project design comes into play. If you expect your dropdown set to be small, you can simply render all of the content on page-load and then use JS/CSS to show/hide each block of content on change of the dropdown.
Alternatively, if you are expecting a larger dataset this could potentially affect your page load times and also make it longer for the browser to render the data (even when it is in a hidden element). In this situation I would look into using AJAX and load in content when you click on a section instead. This is slightly more complex but is;
A good learning exercise
More efficient in the long-term
EDIT:
If you're wanting to go down the show/hide route. This is simple enough using jQuery. There are a few options you could take however I would suggest toggle as a start - see docs here
For AJAX, this will take a bit more reading into. I would also suggest using jQuery's ajax function - see docs here
My Problem I am writing an app for internal use at my pharmacy. I am gathering some usage data from multiple pharmacy systems to help manage inventory. 95% of the records I can automatically parse how many tablets are used every day, but there are some that require user input. This input consists of 3 fields (date, time, number of tabs) for an unknown number of records. For example, twice a day would have 6 records for 3 days, whereas 3 times a day would have 9.
My Current Solution The user selects the records to process and starts the procedure. Any records that can be automatically processed are taken care of. Any records requiring user input are stuck in a table. Upon refresh of the page, an Ajax request checks the table for any records. If a record is present, a modal is shown to the user to allow their input. The input form has a "new record" button that shows another round of the 3 fields, then the data is POSTed to a php script. The script processes the data and removes the affected record. If multiple records, the ajax script pops another modal. This continues until the table is empty.
Help There has to be a more elegant solution out there. I've look at several CRUD grids, but most seem to be about showing and editing data, not about general data entry.
Sorry for the wall of text.
Do you mean something like this
http://www.labs.mimmin.com/inlineedit/
http://dev.iceburg.net/jquery/tableEditor/example_new.php
I found it on google by using 'jquery inline editable table'
I know Yii has a nice admin interface specifically fast input, but I sense you wrote the code yourself, transferring to Yii might be a bigger challenge that solving this in a nice way.
good luck
I am using php, html, css to create a bingo game (There will be nxn boxes. It will be filled in random order for 2 players. Players has to select numbers one by one. One who fills up rows or columns or diagonals five times wins the game).
I created player1.php and player2.php. I am having 9 boxes and populating it from databases. If user clicks a button I'll update the corresponding values as 0 so that when page loads I'll disable the button if the text is 0.
If player1 clicks a button in player1.php, it should reflect in player2.php. How can I do that? Is that possible by reloading page every second? Is it good to do that?
As short answer: no it is not.
Pure PHP is not the most suited for interactive game like that but there are few things you can do.
You could use javascript with Ajax to do this. Let's say you have X players (each using playerX.php although i would put it into player.php and determine each player by GET parameter or something). When one of the player clicks a link, it goes a server-side script, in PHP (possibly using Ajax if you want), that updates your database.
Now the tricky, each player page 'asks' the server every certain amount of time for the state of the game, and updates the page accordingly. The easiest way to do this is create a script (lets call it state.php) that will output data from your database using JSON. You can read the request using ajax and update your page using javascript.
I suggest you read about jQuery and Ajax (which can be also used with jQuery).
If you want to avoid having to refresh the page each time, learning javascript and ajax is your best bet.
Screenshot mockup: http://tinypic.com/r/y2qex/5
Problem: I have a table that has 53 columns; one for each week of the year, plus one with the user name. It will have anywhere between 10 and 80 rows, depending on the number of users for each area.
The users need to be set a “flag” for each week, such as Annual Leave, Training etc.
I currently have a table, which has a select box in each cell. The problem is this works for 5 rows, but once I start getting 20+ rows, the browser wont open the page, because there are just too many select boxes.
Whatever new selections are picked must be able to be queried, so I can save them in my DB.
What I’m after are some generic ideas (i.e. not specific code) on how I can better solve this problem. Once I get a good idea, I’ll go off an work out the exact coding.
My ideas so far:
- Make all cells text only, with the current selection, then have an ‘edit’ option beside each user, which opens their row as a modal window which can be editted
- Make all cells have a “onClick” event, causing a dropdown list to be generated at the point of click
But I’d be keen to hear how other people might approach/solve this problem?
If the options are the same for many select boxes, you could consider using one datalist for all of them, this would be more performant, and I'm guessing allow you to have more per page. Unfortunately this is an HTML 5 feature, so it would not be backwards compatible with all browsers.
http://www.w3schools.com/html5/tag_datalist.asp
Other than that, you could consider pagenating your table if it gets over a certain number of columns. Or do like a tumbr thing, where more columns load via ajax if they scroll to the right far enough. You idea also should work.
You might want to look at using a calendar feature, I'm sure there's a ton of Javascript calendars out there. I also have had a lot of success lately using DataTables. You could use DataTables + jEditable to create a click to edit table representation, that when clicked gives you a select box, but otherwise shows only text.
Perhaps you could have a single hidden select box on the page and display it on a cell when clicked, and handle the result of the click by writing a data-attribute to the cell, and perhaps doing a simultaneous XHR?
You could also just have a bunch of hidden form elements, but that would be gross.
Implementation-wise, you could do it with a single event handler attached to the table, with each cell having data-attributes representing name and week.
Anyway, this should be performant, even though it would require an extra 20 or so lines of js.
Maybe something like this could work for you:
var td=document.getElementsByTagName('td');
for(var i=0; i<td.length; i++)
{
td[i].id='cellID_'+i;
td[i].onclick=function()
{
//make menu appear on this element id
}
}
I have searched online for this issue, but the results are mostly based around Excel.
I have a webpage that has a list of videos. Every time someone clicks on a link, they are taken to a separate page where they can view a video. I have a table in my mysql database that links video id to views. I would like to increment the views column every time someone clicks on the link.
I know how to do this on the database side, but I am trying to figure out how to trigger the DB operation via PHP. I thought about having a script at the top of the page that calls the stored procedure to update the tally everytime the page is loaded, but the problem with this is that the video doesn't start automatic ally when the page loads. Users have to manually click on "play".
Why not write an Update query on the table which gets called everytime a link is clicked?
It is a little confusing where you want to increment the counter. You give three situations:
When a user clicks a link to a particular video's page
When a user loads a particular video's page
When a user clicks play on a video
1 & 2 wouldn't give an accurate count of those who actually watched the video, so I'll choose that you meant 3.
It depends on your video player then. If the player has a way to hook a javascript function to the start of a video, then you can use that to make an ajax request back to a server page that updates your database. If the player has no hooks then you're limited to on page load, which will be less reliable.
Does this help? If I miss understood the question, please clarify by updating the question or adding comments. PS. adding code of what you've tried goes a long away as well.