Solved

Dynamic Display Text on Drop Down Selection

Posted on 2010-08-14
4
494 Views
Last Modified: 2013-12-13
A little background: I am using Dreamweaver and PHP MySQL to build a PHP appointment request form.

I am using Webassist's Dynamic Drop Downs extension to sort out the drop downs but would like an additional bit of functionality. Here is the basic set up, Choose Surgery, Choose Date, Choose Practitioner - Send (which uses POST to send to a contact.php form to validate then email). All these will be dynamically filled from the database (not finished yet).

What I would like is that on the second drop down, after Surgery and Date are known, to populate a small table on screen to highlight the surgery times and availability for that day.

So when someone selects a date in the date dropdown, use onChange (or something. Note that I do not know any Javascript) to populate an information only area that says 9am - full and 12pm busy... I would like to be dynamic with no reloading if possible. I have seen a detailed solution involving a button and GET the same page to reload but my issue is that the drop downs are already within a form that is using POST to send - not sure how this would affect it.

The availability data is all ready on the database - it is just a case of writing the write query and loading it dynamically.

Any advice appreciated.
0
Comment
Question by:alexking
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
KiasChaos83 earned 500 total points
ID: 33438713
Take a look at this page, I think it almost directly does what you want..

http://www.w3schools.com/PHP/php_ajax_database.asp
0
 

Author Comment

by:alexking
ID: 33442347
Hi, thanks for that link - that is exactly what I would like to do.

I am trying to adapt it to my site but have come up with a little problem. I can get the new information table header to appear onChange of the drop down but no data comes through, instead I get this message:

[16-Aug-2010 00:17:42] PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /.../.../getuser.php on line 24.

As far as I can see from that it must be tracking back to $q which in turn must be a problem picking up the q from the first page but I cannot quite see where is is going wrong. Any ideas?
<?php
$q=$_GET["q"];

$con = mysql_connect('***connection***', '***user***', '***password***');

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("vsconnect", $con);

$sql="SELECT * FROM surgery_table WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>SurgeryStart</th>
<th>SurgeryEnd</th>
<th>Availability</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['surgey_1_start'] . "</td>";
  echo "<td>" . $row['surgery_1_end'] . "</td>";
  echo "<td>" . $row['surgery_1_busy_string'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

Open in new window

0
 

Author Comment

by:alexking
ID: 33442399
Ok, I have spotted one of my errors. in Line 13 above, I had not replaced 'id' with a relevant field name from my database.

Now that I have done that nothing comes up under the headers as expected (and there is data in the database) and no PHP error at all comes up in the log.

Wondering if the following would affect it - the onChange drop down box is a display of dates from the database. I have used the PHP date() function to reformat these dates from MySQL standard for display purposes. Is it now trying to match the reformated date back to the original mysql date as stored in the database?

If this is the case, how do I get around it - Can the query convert it back or check for all formats of that date?

Thanks.
0
 

Author Comment

by:alexking
ID: 33457602
Hi KiasChaos83,

Have you any ideas on my follow up questions or should I request help from someone else?

Thanks.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

770 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