creating product catagories

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AaronL
    New Member
    • Jan 2007
    • 99

    creating product catagories

    Hello,

    I am developing an e-commerce system and I want to be able to create catagories and subcatagories for items. I have the basics down however I may be making things too complicated. First I select a parent catagory and the page sucessfully brings me to the subcatagory screen, however anything past that, the catagory id variable is not being passed back to the application. Here is the code, hopefully someone can understand what I'm trying to do and figure out what's wrong, my brain is about to explode. Thanks again!

    Code:
    $catid = $_POST['catid'];
    $catdesc = $_POST['catdesc'];
    echo "<h1>Catagory ID: " . $catid . "</h1>";
    if ($catid == '') 
    {
      $buildsql = "SELECT * FROM catagories WHERE parent=0";
      $result = mysql_query($buildsql);
      $numrows = mysql_num_rows($result);
      if($numrows <= 0)
      {
        echo "<h1>There are no catagories!</h1>";
      }
      echo "<br><br><form action='catagory.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Parent Catagory</b></td></tr>";
      echo "<tr><td align='center'><select size='10' name='catid'>";
      while($rowset = mysql_fetch_array($result))
      {
        echo "<option id=" . $rowset[catid] . " value=" . $rowset[catid] . ">" . $rowset[description] . "</option>";
      }
      echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>";
    }
    else
    {
      //find sub-catagories
      $buildsql = "SELECT * FROM catagories WHERE catid=" . $catid;
      $result = mysql_query($buildsql);
      $rowset = mysql_fetch_array($result);
      $catdesc = $catdesc + $rowset[description] . " ->";
      $buildsql = "SELECT * FROM catagories WHERE parent=" . $catid;
      $result = mysql_query($buildsql);
      $numrows = mysql_num_rows($result);
      If($numrows <= 0)
      {
        echo "<h1>code your submit catagory here!</h1>";
      }
      else
      {
        echo "<br><br><form action='catagory.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Sub-Catagory</b></td></tr>";
        echo "<tr><td align='center'><select size='10' name='catid'>";
        while($rowset = mysql_fetch_array($result))
        {
          echo "<option id=" . $rowset[catid] . " value=" . $rowset[catid] . ">" . $rowset[description] . "</option>";
        }
      echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>";
      }
    }
    mysql_close($con);
    My code is easy to laugh at considering I'm quite a newbie but no offence taken LOL!
  • AaronL
    New Member
    • Jan 2007
    • 99

    #2
    Oh yeah, here is the URL to show you what is happening

    Comment

    • prabirchoudhury
      New Member
      • May 2009
      • 162

      #3
      creating product catagories

      hey
      you do have couple of bad practice on declaring variables and spelling


      solution

      Code:
      $catid = $_POST['catid']; 
      $catdesc = $_POST['catdesc']; 
      
      //call the function
      find_category($catid);
      
      function find_category($catid){
      	echo "<h1>Catagory ID: " . $catid . "</h1>"; 
      if ($catid == '')  
      { 
        $buildsql = "SELECT * FROM catagories WHERE parent=0"; 
        //echo $buildsql;
        $result = mysql_query($buildsql); 
        $numrows = mysql_num_rows($result); 
        if(!$numrows > 0) 
        { 
          echo "<h1>There are no catagories!</h1>"; 
        } 
        echo "<br><br><form action='edit.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Parent Catagory</b></td></tr>"; 
        echo "<tr><td align='center'><select size='10' name='catid'>"; 
        while($rowset = mysql_fetch_array($result)) 
        { 
          echo "<option id=" . $rowset[catid] . " value=" . $rowset[catid] . ">" . $rowset[description] . "</option>"; 
        } 
        echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>"; 
      } 
      else 
      { 
      
      //###you cant use same variables name for two different query before taking off the values.
        //find sub-catagories 
        $buildsql = "SELECT * FROM catagories WHERE catid=" . $catid; 
        $result = mysql_query($buildsql); 
        $rowset = mysql_fetch_array($result);
       
        $catdesc = $rowset[description] . " ->";
        echo  $catdesc;
      
        $buildsql2 = "SELECT * FROM catagories WHERE parent=".$catid; 
        $result2 = mysql_query($buildsql2);
        echo "<br>". $buildsql2;
        $numrows2 = mysql_num_rows($result2); 
        If(!$numrows2 > 0) 
        { 
          echo "<h1>code your submit catagory here!</h1>"; 
        } 
        else 
        { 
          echo "<br><br><form action='catagory.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Sub-Catagory</b></td></tr>"; 
          echo "<tr><td align='center'><select size='10' name='catid'>"; 
          while($rowset2 = mysql_fetch_array($result2)) 
          { 
            echo "<option id=" . $rowset2[catid] . " value=" . $rowset2[catid] . ">" . $rowset2[description] . "</option>"; 
          } 
        echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>"; 
        } 
      }
      	
      }
      that shoud wrk fine ..

      Comment

      • AaronL
        New Member
        • Jan 2007
        • 99

        #4
        Still has the same problem, I looked over everything as far as spelling with no problems, it has something to do with the form not posting correctly

        Comment

        • AaronL
          New Member
          • Jan 2007
          • 99

          #5
          I resolved the problem, apparently the post method has some issues. I used method='get' in my form instead and got the result I wanted.

          Comment

          Working...