Using innerhtml

M

Mtek

Hi,

This is the content of my DIV now:

echo " <div class='innerb'>";
echo " <table class='tabletwo'>";
$select = mysql_query("SELECT row_id, name, address,
city, state, guests, seating, comments
FROM reservations
WHERE res_date =
STR_TO_DATE('$pdate','%m/%d/%Y')
ORDER BY row_id");
$x=0;
while ($row = mysql_fetch_array($select)) {
$x++;
echo " <tr>";
echo " <td class='td1' scope='row'>$x</td>";
echo " <td class='td2'>".$row['name']."</
td>";
echo " <td class='td3'>$address</td>";
echo " <td class='td4'>$city</td>";
echo " <td class='td5'>$state</td>";
echo " <td class='td6'>".$row['guests']."
Guests<br>".$row['seating']." in Section A <br>".$row['comments']."</
td>";
echo " </tr>";
}
echo " </table>";
echo "</div>";

We want to refresh the DIV (innerb) without refreshing the page, and
if we do not have to use ajax either.

So, the user selected the date ($pdate) from the combobox, it is used
to query the database, and the DIV is refreshed. I know this can be
done, but it is just a matter of finding the code or something
similar......

Thanks,

John
 
S

SAM

Mtek a écrit :
Hi,

This is the content of my DIV now:

no, that is the code given to the server
we need the code received by the browser
echo " <div class='innerb'>"; (snip)
echo "</div>";

We want to refresh the DIV (innerb) without refreshing the page, and
if we do not have to use ajax either.

you'll certainly need Ajax
or to send the form and get-it back
So, the user selected the date ($pdate) from the combobox,

what is a "combobox" ?
where it is ?
I know this can be
done, but it is just a matter of finding the code or something
similar......

<http://developer.mozilla.org/en/docs/AJAX>
 
M

Mtek

Mtek a écrit :



no, that is the code given to the server
we need the code received by the browser







you'll certainly need Ajax
or to send the form and get-it back


what is a "combobox" ?
where it is ?


<http://developer.mozilla.org/en/docs/AJAX>


The combo box is in another part of the screen. The page is rather
large. It is not a form. It just has one combo box, and once the
user selects an item, I want the script to get the results from MySQL
and display them, without having to redraw the entire page.......

I know this can be done, I just do not know how.....

John.
 
T

Tom Cole

The combo box is in another part of the screen.  The page is rather
large.  It is not a form.  It just has one combo box, and once the
user selects an item, I want the script to get the results from MySQL
and display them, without having to redraw the entire page.......

I know this can be done, I just do not know how.....

John.- Hide quoted text -

- Show quoted text -

As mentioned in a previous post you have only two options if you do
not want a total page refresh...

1). To bring over not only the options, but also the results of each
option, and generate the entire page at once storing the results in a
series of hidden div elements. Then when they select an option make
that matching div visible. or...

2). Query the server when an option is selected. If this is your
choice then you must either use XMLHttpRequest and process the results
in your callback handler or put your combo box in a form and set the
target of the form to a (i)Frame.

Unless you are dealing with a script that is being called from a
different domain I would use XMLHttpRequest as any modern browser that
can do one, can also do the other as they both require Javascript and
all modern browsers support XMLHttpRequest in one form or another.

If you choose method 2 (the (i)Frame method) your return code can
include javascript that calls javascript methods in the parent frame.

You're not going to be able to include PHP code inside your HTML and
have it magically generate results for you on the client side.

HTH.
 
M

Mtek

As mentioned in a previous post you have only two options if you do
not want a total page refresh...

1). To bring over not only the options, but also the results of each
option, and generate the entire page at once storing the results in a
series of hidden div elements. Then when they select an option make
that matching div visible. or...

2). Query the server when an option is selected. If this is your
choice then you must either use XMLHttpRequest and process the results
in your callback handler or put your combo box in a form and set the
target of the form to a (i)Frame.

Unless you are dealing with a script that is being called from a
different domain I would use XMLHttpRequest as any modern browser that
can do one, can also do the other as they both require Javascript and
all modern browsers support XMLHttpRequest in one form or another.

If you choose method 2 (the (i)Frame method) your return code can
include javascript that calls javascript methods in the parent frame.

You're not going to be able to include PHP code inside your HTML and
have it magically generate results for you on the client side.

HTH.

No, cannot include PHP on the client side, but how about calling a PHP
routine on the server and returning the results? I've seen simple
examples of this, though mine is a bit more complex......

John.
 
T

Tom Cole

No, cannot include PHP on the client side, but how about calling a PHP
routine on the server and returning the results?  I've seen simple
examples of this, though mine is a bit more complex......

John.- Hide quoted text -

- Show quoted text -

That's where XMLHttpRequest comes in, that or the form submission
option. AFAIK there's no other way for a browser to initiate a server
request. So where are the simple examples you've seen, maybe that
would help enlighten me to your specific task.

Is it that you don't know/want to learn XMLHttpRequest or do you
really think there's an easier way? If you're uncomfortable with the
idea, you're pretty much stuck with encapsulating your select within a
form and plain ol' submitting the form, having PHP generate your
updated response page. But without a complete page refresh, you're
going to have to intiate an XMLHttpRequest, or generate a form
submission to an (i)Frame.
 
M

Mtek

Yes, they call that AJAX.

Hmmm....I was trying something like this. Can you tell me where I'm
wrong. I thought it would work. I'll try reading up on AJAX, but I
was curious about this method. It give me an error about the reg_date
not being defined in the PHP script:

..
..
..
<script>
function getrows(reg_date) {
document.getElementById("innerb").innerHTML = XMLHttpRequest("URL/
viewrows.php");
}
</script>
..
..
..
<?
echo "<SELECT NAME='reg_date' onChange=
\"Javascript:getrows(this.value);\" size=1>\n";
$result = mysql_query("SELECT
DISTINCT(DATE_FORMAT(reg_date, '%m/%d/%Y')) FROM reg_data ORDER BY
reg_date;");
while ($rows = mysql_fetch_array($result)) {
echo "<OPTION>";
echo $rows['reg_date'];
echo "</OPTION>";
}
echo "</SELECT>\n";
?>
..
..
..

<?
echo " <tbody>";
echo " <tr>";
echo " <td colspan='6'>";
echo " <div class='innerb'>";
echo " <table class='tabletwo'>";
include('viewrows.php');
echo " </table>";
echo "</div>";
echo "</td></tr>";
echo "</tbody>";
echo "</table>";
?>
..
..
..

Thanks for everyone's help so far......

John
 
C

Captain Paralytic

Yes, they call that AJAX.

Hmmm....I was trying something like this. Can you tell me where I'm
wrong. I thought it would work. I'll try reading up on AJAX, but I
was curious about this method. It give me an error about the reg_date
not being defined in the PHP script:

.
.
.
<script>
function getrows(reg_date) {
document.getElementById("innerb").innerHTML = XMLHttpRequest("URL/
viewrows.php");
}
</script>
.
.
.
<?
echo "<SELECT NAME='reg_date' onChange=
\"Javascript:getrows(this.value);\" size=1>\n";
$result = mysql_query("SELECT
DISTINCT(DATE_FORMAT(reg_date, '%m/%d/%Y')) FROM reg_data ORDER BY
reg_date;");
while ($rows = mysql_fetch_array($result)) {
echo "<OPTION>";
echo $rows['reg_date'];
echo "</OPTION>";
}
echo "</SELECT>\n";
?>
.
.
.

<?
echo " <tbody>";
echo " <tr>";
echo " <td colspan='6'>";
echo " <div class='innerb'>";
echo " <table class='tabletwo'>";
include('viewrows.php');
echo " </table>";
echo "</div>";
echo "</td></tr>";
echo "</tbody>";
echo "</table>";
?>
.
.
.

Thanks for everyone's help so far......

John

This reall belongs in a php group, but try this
$result = mysql_query("SELECT
DISTINCT(DATE_FORMAT(reg_date, '%m/%d/%Y')) reg_date FROM reg_data
ORDER BY
reg_date;");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top