Solved

Dynamic Display Text on Drop Down Selection

Posted on 2010-08-14
4
502 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
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 …

691 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