Jump to content

Archived

This topic is now archived and is closed to further replies.

drunknbass

php attributes cart

Recommended Posts

can someone check out my code..
i got it to work kinda rouch, but i know the code is super sloppy because if i try and edits to the table the info displays in it goes all out of whack, im sure theres a way to shorten this.
basically what this does is look in the table classes and checks to see if there is any data in there for the current productid ($product)
then it looks for class options in another table to display all the options for that class. eg.
color: Black
Red
grey


thenit loops to get all the product classes.
i got it to work, keep in mind the php to edit and add fields are not there yet. i was simply trying to pull the data and display it at this point. i have a feeling since the code is sloppy when that point comes its going to give me headaches, so i wanted to double check what ive done so far and see if its good.

database info is an include file
[code]
// start attribute section

echo "<h3><b><blockquote>Product Options</blockquote></b></h3><FORM ACTION=\"edit_product.php?product=$product\" METHOD=\"POST\">
<table align=center width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td bgcolor=\"$colour_2\">
<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">";
// get option boxes
  $result = mysql_query("select * from ".$prefix."store_classes where productid = $product");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
             $classid = $row["classid"];
             $productid = $row["productid"];
             $class = $row["class"];
             $classtext = $row["classtext"];
             $orderby = $row["orderby"];

  $sql_class_options = "select * from ".$prefix."store_class_options where classid = $classid";
             $result1 = mysql_query ($sql_class_options);
             $row1 = mysql_fetch_array($result1);
             $optionid = $row1["optionid"];
             $option_name = $row1["option_name"];
             $price_modifier = $row1["price_modifier"];
                 
echo "<tr bgcolor=\"$colour_3\"><td width=\"70\" valign=\"top\"><b>$class</b></td>";
    echo "<td width=\"400\" valign=\"top\">";
    
    $reclist = mysql_query("SELECT option_name FROM ".$prefix."store_class_options where classid = $classid")
               or die(mysql_errno()." : ".mysql_error());

for ($j=0; $rec=mysql_fetch_array($reclist); $j++){
     printf("<input name=\"$optionid\" type=\"text\"  class=\"file\" value=\"%s\" />&nbsp;$ +/-:<input name=\"Modifier\" type=\"text\" class=\"file\" size=\"6\" value=\"\" />&nbsp;&nbsp;<a href=
'edit_product.php?product=$product&edit=$optionid')\">Save</a>&nbsp; <a href=\"javascript:decision('Are you sure you want to delete this attribute? Click OK to continue!',
'edit_product.php?product=$product&del=$optionid')\">Delete</a> <br>\n",$rec["option_name"]);  
}

echo "<hr><input name=\"$optionid\" type=\"text\"  class=\"file\" value=\"\" />&nbsp;&nbsp;<a href=\"javascript:decision('Are you sure you want to add this attribute? Click OK to continue!',
'edit_product.php?product=$product&add=$value')\">Add</a>";    
    
    echo "</td>";
    }
    
    echo "</tr></table></td></tr></table></FORM>";

echo "<h3><b><blockquote>Add New Option Category</blockquote></b></h3>";
echo "<table align=center width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
            <tr><td bgcolor=\"$colour_2\">
<table width=\"100%\" align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">
  <tr bgcolor=\"$colour_3\"> <td width=\"70\" valign=\"top\"><b>Option Name:</b></td>
    <td width=\"400\" valign=\"top\"><input name=\"newclass\" type=\"text\"  class=\"file\" value=\"\" />&nbsp;&nbsp;<INPUT class=\"submit\" TYPE=\"submit\" name=\"$newclass\" VALUE=\"Save\"> </td></tr></table></td></tr></table>";
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.