Popular Posts

There was an error in this gadget

Oct 12, 2011

Show multiple labels in combobox in php


function comboFurn($id)
{
   // echo "Testid - $id" ;
 

  // Searching for Levels of Categories
$checkParent = mysql_query("Select page_parent_id as parentid from psgfurn_pages where id = '$id' ") or die(mysql_error());
$dataParent = mysql_fetch_object($checkParent);

if ($dataParent->parentid !=0)
{
alert("1 yes");
$checkParent1 = mysql_query("Select page_parent_id as parentid from psgfurn_pages where id = '$dataParent->parentid' ") or die(mysql_error());
$dataParent1 = mysql_fetch_object($checkParent1);

if ($dataParent1->parentid !=0)
{
alert("2 yes");
$checkParent2 = mysql_query("Select page_parent_id as parentid from psgfurn_pages where id = '$dataParent1->parentid' ") or die(mysql_error());
$dataParent2 = mysql_fetch_object($checkParent2);

if ($dataParent2->parentid !=0)
{
alert("3 yes");
$mainCategory = "";
$parentCategory = "";
} else {
$mainCategory = $dataParent1->parentid;
$parentCategory = $dataParent->parentid;
}

} else {
$parentCategory = $id;
$mainCategory = $dataParent->parentid;
}

} else {
$parentCategory = "";
$mainCategory = $id;
}


// End Category




//alert("Main Category - $mainCategory /n Parent Category - $parentCategory");

/*   $only_main = $only_main;
   $layer = $layer;



if(!empty($only_main)){
$aq = "AND id = $only_main";
}
*/
// For Main Category
    $q = mysql_query("Select id, page_name from psgfurn_pages where _group ='main'") or die(mysql_error());

    while($d = mysql_fetch_object($q))
    {
$selected = "";
$categoryMessage = "";
$value = $d->id;

/* if($chk_main_layer == 1){

}else{

  }*/
($d->id == $mainCategory)  ?  $selected = "selected" : $selected = "";
if ($d->id == $id)
{
$categoryMessage = " (Dont Select)";
$value = $only_main;
}

echo "<option value='$value' $selected>$d->page_name $categoryMessage</option>";


// For 2nd Level Category
$q2 = mysql_query("Select id, page_name from psgfurn_pages where parentid = '$d->id' and _group = 'sub' ") or die(mysql_error());
if (mysql_num_rows($q) !=0)
{
while($d2 = mysql_fetch_object($q2))
{
$selected = "";
$categoryMessage = "";
$value = $d2->id;

($d2->id == $parentCategory)  ?  $selected = "selected" : $selected = "";


if ($d2->id == $id)
{
$categoryMessage = " (Already Selected)";
$value = $d2->id;
}

echo "<option value='$value' $selected>&nbsp;&nbsp;&nbsp;&nbsp; - $d2->category_name $categoryMessage</option>";


// For 3rd Level Category
/*$q3 = mysql_query("Select id, category_name from psgfurn_category where parentid = '$d2->id' and _group = 'sub'  ") or die(mysql_error());

if ((mysql_num_rows($q3) !=0) && ($layer != 2))
{
while($d3 = mysql_fetch_object($q3))
{
if ($d3->id != $id)
echo "<option value='$d3->id' >&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; -- $d3->category_name</option>";
// echo "<option value='$d->id-$d2->id-$d3->id' >&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; -- $d3->category_name</option>";
}
}*/

}
}

    }

//End Combox Box Looping
}

No comments:

Post a Comment