Where can I learn how to do live queries? - php

I'm trying to get data from MySql, parse it via php and echo it in json, then jquery will grab the new data and will update the table with the new data.
I have a basic table with basic data, I'm just trying to display my data dynamically for my users. When they select an option from the dropdown menu, the table will update with the new info.
I can grab the data and encode it to json. The problem I'm having is the jquery part. I don't know how to call the php json data and update the table.
I found datatables.net and their plugin is way more than what I need. I just need a simple example so I can start from there. Can someone show me a simple example of doing live queries?
Thanks!

have you tried getting a look at
http://datatables.net/release-datatables/examples/data_sources/server_side.html
update:
take a look at
http://ptheart.com/beta/testdatatables.php
and let me know if this helps.
update:
then you should try jqgrid

Related

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

Pass data read from a database to a javascript function privately

I am using the amCharts javascript library to show some data charts in my website. I want to read the data that will be in the charts from a database.
I'm reading the data with and after that making a call to the javascript function like this:
<?php
echo '<script language="javascript">makeGraph(' . json_encode($data) . ')</script>';
?>
I am getting the results I want this way, but if a client look in the source code of the website, he will see all the data from the database instead of $data since you are not in the server anymore.
So the question is: how can I read and use all the data without exposing it publicly? Because I can not really figure out any other way to do it now.
Thank you very much
If you don't want users to see your data, then don't use JavaScript to process it. Create the charts in php on your server and display the results only.

JQ-GRID implementation in php file

Hi friends i am working on JQ-GRID. I want to show Image in specific column, But i don't know how to attach image in JQ-GRID. Can anybody help me or please send me some links, thanks
jqgrid is a feature monster. I tell this everybody who asks about it.
When jqgrid loads, a function is called which actually gets the data you want to display.
This is normally an ajax call to your php. As a result set of this function, you can just use xml or json.
I prefer json, so I build my result array and do a echo json_encode($myarray)
jQuery("#your_grid_id").jqGrid({ url : '/ajax/getjqgriddata.php'})
Now displaying pictures, there are different ways you can do that. You can either generate a <img src="wherever/mypicture1.png"></img>-link and hand it over in your result, or encode your picture binary data with base64 and deliver it with your result.
A more addvanced way is to use an so called formatter and just returning a id for the image.
This depends on you, but I would suggest to get confident with jqgrid, experiment with returning -links to get a feeling how jqgrid works.
There is plenty of good documentation at:
http://trirand.com/blog/jqgrid/jqgrid.html
Just take a look at it.

Adding rows to MySQL db and showing DIVs with jQuery without refreshing a page

I am using some PHP script to add some data from a complex form to MySQL db and then showing it all in some HTML table. Everything works just fine, but I would like to 'upgrade' my script with jQuery and (I suppose) AJAX.
What I would like to do is when user submits data, the row (or <div>) shows up in the HTML table without refreshing a page. Form and table are on same page, of course...
Some guidelines would be really helpful because I'm not sure should I even use AJAX or something else for my needs. Links for some tutorials will be also great :)
Thanks a lot for any help!
An easy way to do this is using jQuery POST method
http://api.jquery.com/jQuery.post/
When the user submits the data, you use jQuery to post the data to a PHP handler, which saves the data to the database and returns a HTML formatted row to add to your table.
Here's a good example:
http://www.jensbits.com/2009/10/04/jquery-ajax-and-jquery-post-form-submit-examples-with-php/comment-page-1/
I had used this tutorial to implement a comment system on one of my projects. It uses ajax and works really well. I believe that this is what you need.
You'll need:
A php page where to submit the form. Ideally this page will return the result as a JSON object (PHP has some handy JSON functions to convert PHP arrays and objects directly to a proper JSON string). Don't forget to include some error information in the JSON object you return. This can have the form:
{
"errorCode": 0,
"result":
{
"var1": value1,
"var2": value2
}
}
Some javascript to submit the form. This can be done nicely with jQuery.ajax, jQuery.post or jQuery.get functions.
Some javascript to handle the result from the PHP script. This will be a callback function that you give to the jQuery.ajax, jQuery.post or jQuery.get functions. This script will either:
display the errors to the user (you can set some text in a div for example using jQuery("#error").html("My error message");)
Insert the row in your table. You can build HTML elements dynamically using jQuery.append and jQuery.html functions.

Pagination with Jquery/Javascript/Ajax and PHP/Mysql

Does anyone know of a link to a site that has a tutorial/code on good way to paginate information coming from a database? (without page refresh) I have spent the better part of the day looking for a site that has what I need. Most are dealing with static/fixed data in the forms of lists etc.
I need one that has something like this for my tables:
Data Data Data Data
Data Data Data Data
Records 1 to 8 of 27 First Previous Next Last
We just implemented a few things using this plugin for JQuery:
Datatables.net
It works on basic html tables and has support for AJAX. Basically you would just write a PHP page that returns a partial result from your database in JSON, etc. The plugin will handle making the AJAX call and displaying the data.
This is only a very partial answer (sorry, not much time atm) but look for the 'LIMIT' command in mysql. It lets you pull back only a certain set of records, say records 11-20. I use that when I do pagination.
Again, this isn't complete, but hopefully it'll help!
I've worked with this one quite a bit. jQgrid... seems to be pretty well maintained.
http://www.trirand.com/blog/

Categories