Solved

Dynamic Display Text on Drop Down Selection

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 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