Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: Online catalog

  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    Lima, Peru
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Arrow Online catalog

    Hi, I am trying to create an online catalog.

    I created a database (MySQL), within it there is a table called "Products". This table has 4 columns, the first stores the codes of each product, the other store special information for each. So far there is no problem.

    The website will sell clothes, I made a horizontal menu where are the types of clothing (eg shirts, trousers, shoes ...). If the user gives click to "shoes" must go to a page showing different types of shoes. This new page is created in HTML, inside it is an area (a big div) where it will receive small squares (small divs where they will store the different models of each shoe). The idea is to fill the area using php to create these smaller div's and with the help of the database put the titles, the different prices and a brief description of every model.

    If someone gives you click to "shoes" will call a php page called "con_shoes.php."

    Code:
    <?php
    
    include('testing.php');
    
    //get categories out of database
    $cat_array=get_categories();
    
    //display as links to cat pages
    display_categories($cat_array);
    
    ?>
    "testing.php" has the following script:

    Code:
    <?php
    include_once('creating_html.php');
    include_once('db_fns.php');
    include_once('products_fns.php');
    include_once('inline.php');
    ?>
    The first one "creating_html.php" is designed to create the whole structure of the page.

    Code:
    <?php
    echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
    echo "<html xmlns='http://www.w3.org/1999/xhtml'>";
    echo "<head>";
    echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
    echo "<title>testing with PHP</title>";
    echo "</head>";
    
    echo "<body>";
    echo "<div id="area_for_product_thumbnails"> (empty space) </div>";
    echo "</body>";
    echo "</html>";
    ?>
    The idea is that within the "empty space" php place each thumbnail for each product according to all of them in the database. Within each one of them will be: 1 image, and different "h1" "h2", and "h3". Within each one must be the data according to each cell of the table in the database. For example, the first "h1" will be "title" and should read the data in the column "title" within the table "products" from the database.

    Database functions: (inside "db_fns.php"):
    Code:
    <?php
    
    function db_connect() {
       $result = new mysqli('mysql', '****, '****', 'mysql');
       if (!$result) {
          return false;
       }
       $result->autocommit(TRUE);
       return $result;
    }
    
    function db_result_to_array($result) {
       $res_array = array();
    
       for ($count=0; $row = $result->fetch_assoc(); $count++) {
         $res_array[$count] = $row;
       }
    
       return $res_array;
    }
    
    ?>
    products_fns.php:
    Code:
    <?php
    function get_categories() {
       // query database for a list of categories
       $conn = db_connect();
       $query = "select productid, title, price, description from Products";
       $result = @$conn->query($query);
       if (!$result) {
         return false;
       }
       $num_cats = @$result->num_rows;
       if ($num_cats == 0) {
          return false;
       }
       $result = db_result_to_array($result);
       return $result;
    }
    
    function display_categories($cat_array) {
    	if (!is_array($cat_array)) {
    		echo "<p>No categories currently available</p>";
    		return;
    	}
    	echo "<ul>";
    	foreach ($cat_array as $row) {
    		$url="show_cat.php?catid=".($row['catid']);
    		$title=$row['title'];
    		echo "<li>";
    		do_html_url($url,$title);
    		echo "</li>";
    	}
    	echo "</ul>";
    	echo "<hr />";
    }
    ?>
    and "inline.php":
    Code:
    <?php
    function do_html_URL($url, $title) {
      // output URL as link and br
    ?>
      <a href="<?php echo $url; ?>"><?php echo $title; ?></a><br />
    <?php
    }
    
    ?>
    To summarize, I have no idea how to make php put existing data in a row within each "h1" "h2" and "h3" of each product model. How to make php create each thumbnail according to the number of rows that exist within the "Products". This is the first time I make a catágolo, I hope maybe someone can give me a push. Many thanks
    Last edited by renzocj; 10-24-2011 at 12:08 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •