I have managed to get to the stage where I need to build some dynamic relational
JavaScript menus, I have the following MYSQL/PHP can anyone help me build the select
menus?
Üç menüleri (Genişlikleri, Yan duvarlar ve Jant) vardır.
<?php
$query_posts = "
SELECT DISTINCT meta_value
FROM $wpdb->posts as wposts, $wpdb->postmeta as wpostmeta
WHERE
wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'Product'
AND wpostmeta.meta_value LIKE '%%%/%%/R%%'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC
";
$result = mysql_query($query_posts) or die(mysql_error());
$ar_widths = array(); // setup array of widths
$ar_sidewalls = array(); // setup array of sidewalls
$ar_rims = array(); // setup array of rims
while($row = mysql_fetch_array($result)) {
list($width, $sidewall, $rim) = explode("/",$row['meta_value']);
$menu[$width][$sidewall][$rim] = 1;
}
$widths = implode('","', array_keys($menu));
print "var widths = new Array(\"$widths\", \"--\");\n";
print "\nvar sidewalls = new Array();\n";
foreach($menu as $width => $sidewall_array) {
$sidewalls = implode('","', array_keys($sidewall_array));
print "sidewalls[\"$width\"] = new Array(\"$sidewalls\", \"--\");";
print "\nvar rims[\"$width\"] = new Array();\n";
foreach($sidewall_array as $sidewall => $rim_array) {
$rims = implode('","', array_keys($rim_array));
print "rims[\"$width\"][\"$sidewall\"] = new Array(\"$rims\", \"--\");";
}
}
?>
PHP Output (only some of it shown here)
Array("480","540","600","650","235","225","245","255","265","275","285","295",
"305","325","345","380","320","360","300","260", "--");
var sidewalls = new Array();
sidewalls["480"] = new Array("65", "--");
var rims["480"] = new Array();
rims["480"]["65"] = new Array("R28", "--");
sidewalls["540"] = new Array("65", "--");
var rims["540"] = new Array();
rims["540"]["65"] = new Array("R28","R30", "--");
sidewalls["600"] = new Array("65", "--");
var rims["600"] = new Array();
rims["600"]["65"] = new Array("R28","R38", "--");
sidewalls["650"] = new Array("65", "--");
var rims["650"] = new Array();
rims["650"]["65"] = new Array("R38", "--");
sidewalls["235"] = new Array("40","45","35", "--");