Solved

Dynamic Display Text on Drop Down Selection

Posted on 2010-08-14
4
484 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now