Jump to content

Getting the categories to show up in a drop down


Guest

Recommended Posts

Ok i am trying to set up a custom products page that the user can select the category then the product in drop down menus. now im not having any problems with the .inc.php getting the information and displaying it i can place echo tags and it will show up t he only trouble is it shows up at the top right of the screen and i cant controll where it is placed. i was trying to take the echo tags out and place the form in the html but i cant figure out how to call the information from the .inc.php file into the form. here is what i have for the .inc.php file without the echo statements

<?php

$products1=new XTemplate 



("skins/".$config['skinDir']."/styleTemplates/content/products1.tpl");



if($_GET['act']=="info"){

$latestProducts = $db->select("SELECT DISTINCT cat_name, cat_id FROM ".$glob['dbprefix']."CubeCart_category");

$selCatID = $_POST['category'];

$selProdID = $_POST['products1'];





//gets category information

for($i=0;$i<count($latestProducts);$i++){

	

  $catID = $latestProducts[$i]['cat_id'];

  $catName = $latestProducts[$i]['cat_name'];

  

  if ($catID == $selCatID) { $selected = "selected"; }

  else { $selected = ""; }

  }



//gets product info

if (is_null($selCatID) == false)

{



	$latestProducts = $db->select("SELECT productId, name FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `cat_id` = $selCatID ORDER BY productId DESC");



	for($i=0;$i<count($latestProducts);$i++){

	

  $prodID = $latestProducts[$i]['productId'];

  $prodName = $latestProducts[$i]['name'];

  

  if ($prodID == $selProdID) { $selected = "selected"; }

  else { $selected = ""; }

  

	}



}



if (is_null($selProdID) == false)

{

	

}



$products1->assign("PROD_NAME",$prodName);

$products1->assign("SELECTED",$selected);

$products1->assign("SEL_PROD_ID",$selProdID);

$products1->assign("CAT_ID",$catID);

$products1->assign("CAT_NAME",$catName);

$products1->assign("PROD_ID",$prodID);

$products1->assign("SEL_CAT_ID",$selCatID);

   	 

}



$products1->parse("products1");

$page_content = $products1->text('products1');

?>

Link to comment
Share on other sites

what ive been able to rule out is the php code works fine it pulls the data and will display it on the screen if you place a form around the php using echo tags. when this gets messed up is when you try to movie it to the .tpl page. because it is in a loop and there is more than one piece of information it will not show in an drop down menu. is there anyway to have one file say a .php file to hold everything on one page? that way the loop would run and populate the drop down menu. this is what it looks like in the .inc.php page when i add the form:

echo "<form name='selCat' action=" . basename($PHP_SELF) . " method='POST'>

	<select name='category' size='1' onchange=selCat.submit()>";

for($i=0;$i<count($latestProducts);$i++){

  

	

  $catID = $latestProducts[$i]['cat_id'];

  $catName = $latestProducts[$i]['cat_name'];

  

  if ($catID == $selCatID) { $selected = "selected"; }

  else { $selected = ""; }

  echo "<option value=$catID $selected>$catName</option>";

}

echo "</select></form>";



if (is_null($selCatID) == false)

{



	$latestProducts = $db->select("SELECT productId, name FROM ".$glob['dbprefix']."CubeCart_inventory WHERE `cat_id` = $selCatID ORDER BY productId DESC");



	echo "<br><form name='selProduct' action=" . basename($PHP_SELF) . " method='POST'>

                        <select name='products' size='1' onchange=selProduct.submit() >";

	for($i=0;$i<count($latestProducts);$i++){

	

  $prodID = $latestProducts[$i]['productId'];

  $prodName = $latestProducts[$i]['name'];

  

  if ($prodID == $selProdID) { $selected = "selected"; }

  else { $selected = ""; }

  echo "<option value='$prodID $selected'>$prodName</option>";

	}

  echo "</select><input type='hidden' name='category' value=$selCatID></form>";

}



if (is_null($selProdID) == false)

{

	echo "<br><form name='submitProd' action='products1.php?act=viewProd&productId=$selProdID' method='POST'>

  <input type='submit' value='View Product Info.'></form>";

}

:huh:

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...