[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

Dynamic Display Text on Drop Down Selection

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
alexking
Asked:
alexking
  • 3
1 Solution
 
KiasChaos83Commented:
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
 
alexkingAuthor Commented:
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
 
alexkingAuthor Commented:
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
 
alexkingAuthor Commented:
Hi KiasChaos83,

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

Thanks.
0

Featured Post

Independent Software Vendors: 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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now