Solved

Reload a php query that is included in html page when select option is pressed.

Posted on 2014-09-09
3
261 Views
Last Modified: 2014-09-20
I have a index.php page that that uses this in the body.
<div id="live-area">
                            <?php include ('assets/php/multibox.php');?>
                                </div>

Open in new window


In that multibox.php i have a div id container that loads my highcharts.
On that same multibox.php i have a query to load the table data.

I have a select option box that is filled by a mysql query on same page.

here is what the options look like
echo "<option value=index.php?id=$row[activity]/$row[app_name]>$row[app_name]</option>";

Open in new window


So when they are clicked they reload the index.php (same page they are included on) and pass id.

I then have this on the multibox.php to check the id
if ($_GET['id'] == '')

So i can change the query based on that id so when the page loads it shows the chart with data for the selected.

SO... my question.

How can i just refresh that php with data for graph?

I did the following but it reloads the entire page into the live-area div.

echo "<select name=category value='' onchange=\"runthis(this)\"></option>";

Open in new window


 <script type="text/javascript">

        function runthis(sel) {
            var page = sel.value;
        $.ajax({
            url: page,
            success: function (response) {
                $('#live-area').html(response);
            }
        });
        }
    </script>

Open in new window

0
Comment
Question by:bignadad
  • 2
3 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40313439
You need to create a page that is called by the ajax function that only contains the data (HTML) for the graph and nothing else
0
 
LVL 2

Accepted Solution

by:
bignadad earned 0 total points
ID: 40313449
i figured it out.

function runthis(sel) {
        var page = sel.value;
        $('#live-area').load('assets/php/multibox.php?id=' + page);
    }

Open in new window

0
 
LVL 2

Author Closing Comment

by:bignadad
ID: 40334220
Firgured out the answer myself
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 7 52
Javascript 2 28
Checking https returns 301 21 30
send email part1 9 28
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question