Notification System that loops through first ten database entries - php

I have looked for days now and cannot seem to find any direct examples of what I am trying to accomplish, that I can reference.
I am trying to create a simple, elegant notification system, that pulls a persons image, name (in text format), and a predefined message (selected from drop down menu), from a database, and then displays the info in an elegant little "profile like" layout, on a webpage or smartphone. The only feature that I want the app to have is an auto refresh setup (using AJAX maybe?) that cycles through the latest ten entries into the database, in a continual loop.
I already have the MySql database set up, as well as the form which supplies the information that I want show, into the database -- but I can't for the life of me figure out how to pull that info into a nice little alert, and get it to cycle through the latest ten database entries.
Thank you so much, in advance, for any assistance you can provide. I'm ok with databases, and Php, but I'm racking my brain trying to figure out how to get it to display and cycle through the first ten entries.
Thanks again!

If you have an id column or some sort of timestamp column, you can use ORDER BY and LIMIT in MySql to extract only the last X recrods.
For example:
SELECT * FROM profiles ORDER BY id DESC LIMIT 10
That will extract the top 10 id's, where in a standard id column, that will be the last 10 records.
As for formating the display - that is way to wide, and there are a lot of ways to do so.

I think you should have PHP file with SQL query SELECT ... ORDER BY id LIMIT 10, and use json_encode to JSON encode the returned array. JSON is easy to use with AJAX with JavaScript.
And about AJAX - I would use jQuery and use jQuery.getJson from PHP file do sleep and loop it
EDIT: On refresh you will do a new JSON parse, and remove last elements of container with cards, and use new elements

Related

Is there a way to store multiple records rather than using multiple rows in MySQL?

I would like to make full use out of MySQL for the purpose of a (web) application I have developed for a chiropractor.
So far I have been storing in a single row for [every year] for what are called progress notes. The table structure looks something like this (progress_note_id, patient_id, date (Y-0-0), progress_note). When the client wishes to append for the year of the current progress notes, he simply clicks at the top of a textarea (html), which I use TinyMCE JavaScript library, to make a new entry date along with the shorthand notes to go at the beginning of the column (progress_note). So far its been working ok, if there are 900+ clients (est.) there could potentially be 1300+ progress notes, for each year since the beginning of the application (2018).
Now the client wishes to be able to see previous progress notes (history), but is unable to modify any previous notes, while still be able to write new ones. The solution I have come up with is to use XML inside the textarea, and use PHP to decipher the new notes from the old ones.
My problem however is if I should have to convert my entire table from a yearly to a daily, that it could take up a lot of time and energy to convert multiple notes into each single rows, (est. 10x) Which could end up being 13,000+ rows. I realize that no matter what method I choose to do is going to be a lot of work. Another way around this perhaps I found was to use XML column type in MySQL to potentially store multiple records, and if I wish to append it, all I would need is PHP to interpret the entire XML and add a new child node, to the beginning. Each progress note is 255 - 500 chars. And in worst case scenario, if the patient was to be 52 times a year (1 for every week), there shouldn't be a large enough overhead.
Is this the correct way to solving this problem? I do wish to keep with MySQL DB and I realize that MySQL is not an intended for XML. And for some clarification, what I hope to accomplish is the same thing I intended to do with current progress notes, but with XML. I believe in ascending order (newer -> oldest).
<xml_result>
<progress_note>
<date>2020-08-16</date>
<content></content>
</progress_note>
<xml_result>
Thank-you for any of your time and for any suggestions.
Firstly, 13000+ is not a problem for mysql. In most case for web application, mysql can handle more than 10m+ records for a single instance with a good performance.
Secondly, you can use either XML or JSON format in a text field and handle the decoding in your application.

Can I display a million record in a html table in one go?

I'm currently creating a web-based system that would have a millions of data after some years (3 years = 1 million record, just guessing).
Now I have a webpage where I display all records in a html table dynamically.
If the time comes can it display these amount of data?
What are the things I need to consider?
What about hardware requirements (for the server probably)?
The set up would be a LAN set up to be use by 7 users simultaneously.
Any help would be appreciated.
Here is a my php code:
my php code
and this is the result:
Result
I guess your browser will crash if you display this inside of a table or list.
The only way i see is to lazy load and keep the DOM as small as possible while scrolling through.
Why do you want to display one million records?
Possible but browser will possibly crash.
Best approach is to have a pagination that will display like, 100 per page maybe, and have a search function.
it's not a human readable ,
you can get all data from the database is possible and saved it in an array
then make search in array and get the result what you want
I am using 1 million cells (not rows) in a plain HTML table.
It takes some time do download the data and some more to render it. But if you really need it you can display it. I don't see a production use case. I only display it to spot inconsistent data. So, not going to prod.
There are multiple component libraries to handle continuous scroll.

Sorting data from MySQL and inserting it into a HTML Table

I am currently monitoring 38 individual LED Lighting current and the data is being displayed/imported to a MySQL table. However, that is not what I want to achieve. I want to instead have a concept similar to a table you see in Stock market, where the values(current) are being replaced every other minute or so. Please do advice on how I am suppose achieve the desired outcome. Thank you.
You can use MySQl Acceding or Descending order and short the values.
like as
SELECT * FROM `table-name` ORDER BY `LED` DESC
I suggest you use some kind of JS graph library.
You can make a PHP script the get you data from the database, and use ajax to reload your data into a graph.
I'm, suggesting using HighChart.
This is a good example: Auto Update Highcharts with Ajax

Multiple result sites (pagenumber buttons)

I have a website were the user types in a city (f.e.: Washington), presses search and via ajax json it gets the entries from my database. I never know how many entries it got, so let's say this time I have 40 entries in my database where it says "Washington". Now a function appends all 40 entries on the site.
How do I get it to show only 4 entries and then add number buttons where the user can go to page "X" to see another 4 entries and so on?
second question:
And how do I tell the script to just add a specific amount of number buttons ( In this case just 10, since 10*4=40 already )?
I don't necessarily need a full code example, just a good explanation on how I can do this (without a plugin).
Here a simple drawing to clarify this:
Thank you very much in advance for any answer.
There is an excellent tutorial on tutsplus covering the kind of pagination as seen on your image. You would just need to modify the sql query in the script to match your requirements, point your ajax url to this pagination script, and ensure the results are returned as json. Hope this helps!
To setup the pagination you would need to use mysql LIMIT & OFFSET, also counting the total number of results and returning that in the JSON to set the correct number of pages in the pagination.
You would also need to pass the page number in the ajax call through a GET parameter so you can set the OFFSET correctly and return the correct page.
I tried some jQuery pagination plugins but they were a little buggy. So I chose pure PHP and made a really simple one myself, since the tutorials seemed a bit too overloaded to me.
I just pass pagenr via GET and in my script a set a specific amour of results to be displayed via Limit $start(=0 if pagenr=1), 10
If the pagenr is bigger then "1" it undergoes a for loop which adds up "10" to "$start" every time.
And with these values and COUNT(*) I do the pagination with for and if loops.

Performance Request PHP

I'm focused on a big problem on my web aplication that uses PHP, Ajax and MySql.
I´ve already developed a script that uses a date-range timepicker for make calendars for each store that i have on my database + the advertisement that will be shown on the place. For each advertisement it will be printed 1 more calendar and in each calendar we have an input to write how many times this advertisement will be shown on that day-input.
When the user choose a daterange on year-to-year with 31 places and 1 advertisement for each place, it will be more than 11000 lines on my foreach, which causes a browser stack, and my database will not be updated.
What can i do to perform this type of foreach script?
Thanks!
I wouldn't recommend having someone selecting 11,000 items at a time. If they were to have something go wrong and start over they would be quite unhappy. Maybe do 3 months at a time or something like that.
The other option if you have to keep it this way is to create arrays for each month maybe and once you are done with a month convert it to a json array so it is one string instead of over 900 individual elements in an array. So when you post you are posting 12 json arrays.
Without showing any code or seeing an example it is a little hard to help.

Categories