Jump to content

stephdowney

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Posts posted by stephdowney

  1. was wondering if anyone could help me with this .....i'm working on a computer not using local host but iss and therefore i need to change these config settings but not sure what to....?

    // setting up the web root and server root for
    // this shopping cart application
    $thisFile = str_replace('\\', '/', __FILE__);
    $docRoot = $_SERVER ("csweb");





    $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
    $srvRoot = str_replace('library/config.php', '', $thisFile);

    define('WEB_ROOT', $webRoot);
    define('SRV_ROOT', $srvRoot);

    any ideas?
    thanks
    steph
  2. Hi I have 2 scripts.....1 which should list all categories in a database and one which should list all products belonging to the category but am getting an error ...here are the tables
    [code]
    CREATE TABLE `products` (
      `product_id` int(5) NOT NULL auto_increment,
      `product_name` varchar(50) NOT NULL default '',
      `cat_id` int(5) NOT NULL default '0',
      `description` text NOT NULL,
      `image` varchar(255) default NULL,
      `amount` float(10,2) NOT NULL default '0.00',
      PRIMARY KEY  (`product_id`)
    ) TYPE=MyISAM COMMENT='Table for collecting product data' AUTO_INCREMENT=3;

    #
    # Dumping data for table `products`
    #

    INSERT INTO `products` VALUES (1, 'blue dress', 2, '', NULL, '30.00');
    INSERT INTO `products` VALUES (2, 'green skirt', 3, '', NULL, '20.00');
    CREATE TABLE `category` (
      `id` int(5) NOT NULL auto_increment,
      `category_name` varchar(50) NOT NULL default '',
      `cat_description` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) TYPE=MyISAM COMMENT='Table for product categary' AUTO_INCREMENT=8;

    #
    # Dumping data for table `category`
    #

    INSERT INTO `category` VALUES (1, 'shoes', '');
    INSERT INTO `category` VALUES (2, 'dresses', '');
    INSERT INTO `category` VALUES (3, 'skirts', '');
    INSERT INTO `category` VALUES (4, 'jeans', '2006-04-13 16:19:03');
    INSERT INTO `category` VALUES (5, 'shirt', '2006-04-19 16:59:05');
    INSERT INTO `category` VALUES (6, 'test', '2006-04-20 11:59:59');
    INSERT INTO `category` VALUES (7, 'yo', '2006-04-20 14:33:30');
    [/code]

    here's my code
    shop1.php
    [code]
    // query database, order alphebatically

    $query ="SELECT * from category order by category_name ";
    $result= mysql_query($query) or die
    ("Could not execute query : $query." . mysql_error());



    while ($row = mysql_fetch_array($result))
    {
    $cat_id=$row['id'];
    $cat_name = $row["category_name"];
    $cat_description = $row["cat_description"];

    echo "<li><b><a href=productlist.php?id=$cat_id>$cat_name</a></b> [ ";

    // Now query products table to see how many listing in each category
    if ($_GET['cat_id'] == $cat_id){
    $get_items = "SELECT product_id, product_name, description FROM products WHERE id=$cat_id order by product_name";
    $result = mysql_query($get_items)or die(mysql_error());

    if (mysql_num_rows($result)<1){
    $display_block = "<P>none</p>";
    }else{
    $display_block .="<ul>";

    while($items = mysql_fetch_array($result)){
    $product_id =$items['product_id'];
    $product_name =$items['product_name'];
    $description =$items['description'];

    $display_block .="<li><a
    href=\"productlist.php?item_id=$item_id>$product_name</a>
    </strong> (\$$description)";
    }
    $display_block .="</ul>";
    }
    }
    }


    // Include the HTML footer file.
    include_once ('includes/footer.html');
    ?>


    and also
    productlist.php

    if(isset($cat_id))
    {
    $query = "SELECT * from products where cat_id='$cat_id' ";
    }

    // Check if there's a budget variable, output correct query

    if(isset($budget))
    {
    $query ="SELECT * from products where amount < '$budget' ";
    }

    // If both variables are not present, output default query

    if(!isset($budget) && !isset($cat_id))
    {
    $query = "SELECT * from products ";
    }

    // execute query
    $result= mysql_query($query) or die
    ("Could not execute query : $query." . mysql_error());

    while ($row = mysql_fetch_array($result))
    {
    $id=$row["product_id"];
    $name=$row["product_name"];
    $cat_id=$row["cat_id"];
    $image=$row["image"];
    $dsc = $row["description"];
    $amout=$row["amount"];

    // query category table for category name.
    $catquery = "SELECT category_name from category where id='$id' ";
    $result2= mysql_query($catquery) or die
    ("Could not execute query : $catquery." . mysql_error());

    $cname = mysql_fetch_array($result2);

    // Now print out the catalog display

    ?><table cellspacing="1" cellpadding="1" border="0" align="center" width="90%">
    <tr>
    <td><b><?php echo "$name"; ?></b>
    <p><?php echo "<b>Category: $cname[category_name]</b><br>$dsc"; ?></p>

    <?php
    if (!(empty($image))) // image field is not empty
    {
    echo "<img src=$image border=0 alt=$name width=150 align=right>";
    }
    ?>

    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="image" src="https://www.paypal.com/en_GB/i/btn/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="business" value="d1340101@qub.ac.uk">
    <input type="hidden" name="item_name" value="green dress">
    <input type="hidden" name="amount" value="20.00">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="GBP">
    <input type="hidden" name="lc" value="GB">
    <input type="hidden" name="bn" value="PP-ShopCartBF">
    </form>

    </td></tr></table>
    <?php

    } // end of while

    ?>
    <?php // Include the HTML footer file.
    include_once ('includes/footer.html');
    ?>
    [/code]

    and i'm getting this error so far
    Notice: Undefined index: cat_id in F:\13401017\website\12\html\shop1.php on line 35

    totally stuck on this so anyhelp wud be much appreciated
    thanks

    [b]EDIT BY OBER: PLEASE USE CODE TAGS WHEN POSTING CODE![/b]
  3. [!--quoteo(post=366524:date=Apr 19 2006, 01:01 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 19 2006, 01:01 PM) [snapback]366524[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    If you want it to expand with no need to refresh the browser or open a link, you would have to use Javascript (and to retrieve all the products from all categories upon page load).

    If not, you can make the a link for each category (like: ?cat=1), retrieve the chosen category ($_GET['cat']) and use this value to find all the products for the category (SELECT * FROM `products` WHERE category = "$_GET['cat']")
    [/quote]


    hey thanks for the help but i'm totally new!!
    any snippets of code ....i kinda understand but dunno how 2 put it all 2gether!
    cheers steph
  4. Hi,
    i'm designing an online shop and have 2 tables in my database (categories and products) I need to have a menu that lists all categories and then when a categorie is clicked it exapnds to show all th products within that category....any help would be great
    thanks
    steph
×
×
  • Create New...

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.