I am hoping someone can point me in the right direction.
I have a need to create a form that requires user selection of choices in 3 SELECT drop down lists.
I have trawled the web forums and youtube etc to try and find a resolution to my problems... tried multiple so called resolutions and have yet to achieve success.
Whether it is something to do with my code or the format of my database I do not know.
Please be kind as I am only a VERY novice programmer and will appreciate any assistance offered.
I have 3 files....
index.php (Form)
loadsubcat.php (PHP processing)
config.php (db connection)
The basics of the files were "borrowed" from user kabiru10 (thank you).
Using kabiru10 "Creating a Dependent Dropdown List with PHP, jQuery and Ajax" example code everything works. It's once I change databases and tables I get stuck and it breaks.
======= CONTENTS of index.php ---------------
====== Contents of loadsubcat.php ===============
====== Contents of config.php ==================
Not Provided
=======================================
====== Partial Database Dump ======================
-- phpMyAdmin SQL Dump
-- version 4.0.8
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 09, 2014 at 11:47 AM
-- Server version: 5.5.29
-- PHP Version: 5.4.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `ozr48210_FitFirst`
--
-- --------------------------------------------------------
--
-- Table structure for table `Locations`
--
=======================================================
- <?php
- include('config.php');
- $query_parent = mysql_query("SELECT DISTINCT State FROM Locations") or die("Query failed: ".mysql_error());
- ?>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Dependent DropDown List</title>
- <script type="text/javascript" src="js/jquery.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#parent_cat").change(function() {
- $.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
- $("#sub_cat").html(data);
- $('#loader').slideUp(200, function() {
- $(this).remove();
- });
- });
- });
- });
- </script>
- </head>
- <body>
- <form method="get">
- <label for="category">Parent Category</label>
- <select name="parent_cat" id="parent_cat">
- <option>Select State</option>
- <option value="<?php echo $row['ID']; ?>"><?php echo $row['State']; ?></option>
- <?php endwhile; ?>
- </select>
- <br/><hr/>
- <label>Sub Category</label>
- <select name="sub_cat" id="sub_cat">
- <option>Select Suburb</option>
- </select>
- </form>
- </body>
- </html>
- <?php
- include('config.php');
- $parent_cat = $_GET['parent_cat'];
- echo "<option value='$row[Area]'>$row[Area]</option>";
- }
- ?>
- CREATE TABLE `Locations` (
- `State` VARCHAR(3) DEFAULT NULL,
- `Area` VARCHAR(23) DEFAULT NULL,
- `ClubID` INT(5) NOT NULL DEFAULT '0',
- `ClubName` VARCHAR(33) DEFAULT NULL,
- `ClubType` VARCHAR(8) DEFAULT NULL,
- `Lattitude` DECIMAL(10,7) DEFAULT NULL,
- `Longditude` DECIMAL(10,7) DEFAULT NULL,
- `ID` INT(1) DEFAULT NULL,
- PRIMARY KEY (`ClubID`),
- UNIQUE KEY `ClubID` (`ClubID`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- --
- -- Dumping data for table `Locations`
- --
- INSERT INTO `Locations` (`State`, `Area`, `ClubID`, `ClubName`, `ClubType`, `Lattitude`, `Longditude`, `ID`) VALUES
- ('NSW', 'Sydney West', 52958, 'Auburn', 'Passport', -33.8474460, 151.0455480, 2),
- ('WA', 'Balga', 52977, 'Balga', 'Passport', -31.8477860, 115.8245160, 5),
- ('NSW', 'Sydney Northern Beaches', 52998, 'Balgowlah', 'Platinum', -33.7931690, 151.2643430, 2),
- ('NSW', 'Sydney West', 53017, 'Bankstown', 'Passport', -33.9320540, 151.0295710, 2),
- ('VIC', 'Melbourne South East', 53037, 'Bayside', 'Passport', -37.9546882, 145.0312471, 4),
- ('NSW', 'Sydney Eastern Suburbs', 53064, 'Bondi (The Edge)', 'Passport', -33.8922310, 151.2477680, 2),
- ('NSW', 'Sydney Eastern Suburbs', 53083, 'Bondi', 'Platinum', -33.8923240, 151.2473300, 2),
- ('VIC', 'Melbourne South East', 53106, 'Brighton', 'Passport', -37.9092540, 145.0119030, 4),
- ('QLD', 'Brisbane Central', 53136, 'Brisbane CBD - Brisbane City', 'Passport', -27.4647970, 153.0290020, 3),
- ('ACT', 'Canberra', 53197, 'Canberra City', 'Passport', -35.2798580, 149.1337130, 1),
- ('WA', 'Cannington', 53212, 'Cannington', 'Passport', -32.0188900, 115.9347500, 5),
- ('QLD', 'Brisbane South', 53241, 'Carindale', 'Passport', -27.5170800, 153.0980070, 3),
- ('NSW', 'Sydney North West', 53267, 'Carlingford', 'Passport', -33.7778210, 151.0520690, 2),
- ('NSW', 'Sydney North West', 53292, 'Castle Hill - Castle Towers', 'Passport', -33.7328193, 151.0049599, 2),
- ('VIC', 'Melbourne South East', 53320, 'Chadstone', 'Passport', -37.8878763, 145.0952034, 4),
- ('VIC', 'Melbourne South East', 53336, 'Malvern Valley', 'Passport', -37.8773090, 145.0829280, 4),
- ('NSW', 'Sydney North Shore', 53360, 'Chatswood', 'Platinum', -33.7957960, 151.1821880, 2),
- ('WA', 'Perth CBD', 53391, 'Brookfield Place', 'Platinum', -31.9544740, 115.8552560, 5);
- Add new comment
- 308 views