Help with dropdown list plugin development
-
Hello all,
I am pretty new to plugin programming for WordPress.
I am looking for help to make a plugin that shows with a short-code on a page
two Dynamic populating dropdown lists from a MySQL table.I have found the following example with html, php and javascript.
Can anyone help to make this work as an WordPress plugin?Thanks for the help.
Hans.main.html
——————————————————
<!doctype html public “-//w3c//dtd html 3.2//en”>
<html>
<head>
<title>(Type a title for your page here)</title>
<script language=”javascript” src=”list.php”></script>
</head><FORM name=”drop_list” action=”yourpage.php” method=”POST” >
<SELECT NAME=”Category” onChange=”SelectSubCat();” >
<Option value=””>Category</option>
</SELECT>?
<SELECT id=”SubCat” NAME=”SubCat”>
<Option value=””>SubCat</option>
</SELECT>
</form></body>
</html>list.php
——————————————————-
<?php
require “config.php”; // database connection details
echo “function fillCategory(){
// this function is used to fill the category list on load“;
$q1=mysql_query(“select * from category”);
echo mysql_error();
while($nt1=mysql_fetch_array($q1)){
echo “addOption(document.drop_list.Category, ‘$nt1[cat_id]’, ‘$nt1[category]’);”;
}// end of while
?>
} // end of JS functionfunction SelectSubCat(){
// ON or after selection of category this function will workremoveAllOptions(document.drop_list.SubCat);
addOption(document.drop_list.SubCat, “”, “SubCat”, “”);// Collect all element of subcategory for various cat_id
<?
// let us collect all cat_id and then collect all subcategory for each cat_id
$q2=mysql_query(“select distinct(cat_id) from subcategory”);while($nt2=mysql_fetch_array($q2)){
//echo “$nt2[cat_id]”;
echo “if(document.drop_list.Category.value == ‘$nt2[cat_id]’){“;
$q3=mysql_query(“select subcategory from subcategory where cat_id=’$nt2[cat_id]'”);
while($nt3=mysql_fetch_array($q3)){
echo “addOption(document.drop_list.SubCat,’$nt3[subcategory]’, ‘$nt3[subcategory]’);”;} // end of while loop
echo “}”; // end of JS if condition}
?>
} //////////////////function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i–)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}function addOption(selectbox, value, text )
{
var optn = document.createElement(“OPTION”);
optn.text = text;
optn.value = value;selectbox.options.add(optn);
}Dump.txt (to create the MySQL tables)
——————————————————–
CREATE TABLEcategory
(
cat_id
int(2) NOT NULL auto_increment,
category
varchar(25) NOT NULL default ”,
PRIMARY KEY (cat_id
)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;—
— Dumping data for tablecategory
—INSERT INTO
category
VALUES (1, ‘Fruits’);
INSERT INTOcategory
VALUES (2, ‘Colors’);
INSERT INTOcategory
VALUES (3, ‘Games’);
INSERT INTOcategory
VALUES (4, ‘Vehicles’);— ——————————————————–
—
— Table structure for tablesubcategory
—CREATE TABLE
subcategory
(
cat_id
int(2) NOT NULL default ‘0’,
subcategory
varchar(25) NOT NULL default ”
) ENGINE=MyISAM DEFAULT CHARSET=latin1;—
— Dumping data for tablesubcategory
—INSERT INTO
subcategory
VALUES (1, ‘Mango’);
INSERT INTOsubcategory
VALUES (1, ‘Banana’);
INSERT INTOsubcategory
VALUES (1, ‘Orange’);
INSERT INTOsubcategory
VALUES (1, ‘Apple’);
INSERT INTOsubcategory
VALUES (2, ‘Red’);
INSERT INTOsubcategory
VALUES (2, ‘Blue’);
INSERT INTOsubcategory
VALUES (2, ‘Green’);
INSERT INTOsubcategory
VALUES (2, ‘Yellow’);
INSERT INTOsubcategory
VALUES (3, ‘Cricket’);
INSERT INTOsubcategory
VALUES (3, ‘Football’);
INSERT INTOsubcategory
VALUES (3, ‘Baseball’);
INSERT INTOsubcategory
VALUES (3, ‘Tennis’);
INSERT INTOsubcategory
VALUES (4, ‘Cars’);
INSERT INTOsubcategory
VALUES (4, ‘Trucks’);
INSERT INTOsubcategory
VALUES (4, ‘Blkes’);
INSERT INTOsubcategory
VALUES (4, ‘Train’);
- The topic ‘Help with dropdown list plugin development’ is closed to new replies.