Results 1 to 13 of 13

Thread: php mysql datafeed help

  1. #1
    Senior Member agua's Avatar
    Join Date
    Sep 2005
    Location
    Pottsville, NSW
    Posts
    531

    php mysql datafeed help

    OK - I'm having a go at building a site from a datafeed using php and mysql.

    The datafeed came in one file with the following field headers:

    id, sku, Brand, category, name, description, price, SalePrice, OnSale, buyurl, keywords, imageurl

    So I built 1 mysql table using those values.

    I am fairly new to programming myself (always using premade solutions) so I am working through this data with Kevin Yanks "building data websites" book.

    What I am looking to do is have the categories displayed on the left and the content on the right (but theres another question - displaying sub-cats split with a "|"?)

    Is it possible for me to produce a datafeed site from this one table, or should I split it as the book says?

    The datafeed has 7500 entries so I was hoping on not doing any edits in the database not the feed I was also planning to make this a quick project but one which I can reuse for other datafeeds.
    I Do Website Design - but I am here to learn all about publishing

  2. #2
    Registered LuckyShima's Avatar
    Join Date
    Jan 2004
    Posts
    207
    Quote Originally Posted by agua
    Is it possible for me to produce a datafeed site from this one table, or should I split it as the book says?
    It is not a large table. What do you mean the book says to split it?

  3. #3
    Senior Member agua's Avatar
    Join Date
    Sep 2005
    Location
    Pottsville, NSW
    Posts
    531
    Well its says to separate categories from articles - Keep them in separate tables and cross reference (relationship database!!)
    I Do Website Design - but I am here to learn all about publishing

  4. #4
    Registered
    Join Date
    Aug 2005
    Location
    ACT, Australia.
    Posts
    77
    You can do it the way it is currently set up. In fact it would be easier than splitting the table.

  5. #5
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    For a quick site, leave it as-is.

    For an advanced one, create an extra category table (with fields 'id', 'categoryname'), and then just use the relevant category_id in the product table (where you have 'category' now). This way, you can expand the category table to include descriptions, meta tags, and be able to keep the management of that seperate from the product table.

    I hope that makes sense!
    Stepping On Wires - the new blog

  6. #6
    Senior Member agua's Avatar
    Join Date
    Sep 2005
    Location
    Pottsville, NSW
    Posts
    531
    OK - I'm making progress - but I'm stuck on the categories

    They are constructed like this:
    Shoes|Mens|Casual|Comfort
    Shoes|Kids|Girls|Infants
    Shoes|Womens|Sandals|Dress
    Accessories|Shoe Care|Shoes Trees
    The code I have so far for showing the categories is
    $cats = @mysql_query('SELECT id, category FROM spa');
    if (!$cats) {
    exit('<p>Error retrieving categories from database!<br />' .
    'Error: ' . mysql_error() . '</p>');
    }

    while ($cat = mysql_fetch_array($cats)) {
    $id = $cat['id'];
    $category = htmlspecialchars($cat['category']);

    echo "<li><a href='index.php?id=$id'>$category</a></li>";
    }
    But that just displays all of the categories - I wanted to have 2 main cats (Shoes and Acessories) and all the rest as levels of sub cats up to 4 deep.

    I have read about using a separate cat table for this and having a catID and Parent ID column - would this be the best way here or is there a way I can use what I have already?
    I Do Website Design - but I am here to learn all about publishing

  7. #7
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    I would explode those category listings out into:

    id, categoryname, parentcategory_id

    So 'Shoes' would have a parentcategory_id of '0'. 'Kids' would have a parentcategory_id equivalent of 'Shoes' id, and so on.

    Then for the products, again just list their category_id of whatever the lowest level category is relevant (such as 'Infants').

    Does that make sense? :-S
    Stepping On Wires - the new blog

  8. #8
    Registered
    Join Date
    Apr 2005
    Posts
    103
    What I do is have parent and child categories, to an unlimited level. So each category has a parentID. Its also an easy way to build breadcrumbs etc.

    I just created a new site actually: http://www.rc-car-planes.com

  9. #9
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    What I do is this.

    1. Insert the enter datafeed into an import table. This is less stressful on the db server.

    The SQL is something like this:

    $sql = "LOAD DATA INFILE '/home/admin/aftp.linksynergy.com/$list[mid]_1193364_mp.txt' INTO TABLE linkshare.import_table FIELDS TERMINATED BY '|';";


    Then, in my products table, I have 4 fields for categories (cat1, cat2, cat3, cat4). And my categories table is like catid, catname, parent.

    I explode the field in my important table to get the 4 categories, then I insert them into the products table in textual format. I know, thats not fully normalized, but in this case where the products table is completely deleted and remade on a weekly basis (from the import table) I'm not really worried about normalization. Plus, normalization would require more queries, and when you're doing millions of products thats alot.

    So anyways. I then build the category table from the products table.

    SELECT distinct(cat1), cat2, cat3, cat4, mid FROM products2

    (manipulation and formatting)

    Insert blah blah

    I have unique indexes setup in the DB to prevent any duplicates.

    Then, on the frontend, category pages are referenced like so: domain.com/category/12897 but the code uses the textual name of the category (plus it's parents) and the merchant id (mid) to query the products DB for what products to list in that DB.


    All told, this is really fricken complicated. Some of the most complex SQL queries I've ever wrote were for my datafeed system.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  10. #10
    Senior Member agua's Avatar
    Join Date
    Sep 2005
    Location
    Pottsville, NSW
    Posts
    531
    nm... I'm confused now

    I already have the mysql table made and data inserted so - where and when do I 'explode' the data?

    Do I remake the table with the data exploded, or do I explode the data whilst it is in the table.

    I'm just going off to read about the explode function
    I Do Website Design - but I am here to learn all about publishing

  11. #11
    Registered
    Join Date
    Apr 2005
    Posts
    103
    explode means spliting the string deliminating by a '|' right?

  12. #12
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    Quote Originally Posted by Snowballer
    explode means spliting the string deliminating by a '|' right?
    Indeed is does, there's even an appropriately named function.

  13. #13
    Registered
    Join Date
    Apr 2005
    Posts
    103
    hehe, yeah in C# its just called Split which is an even better name since that is what PHP uses to describe explode's functionality "explode -- Split a string by string"

    although explode is more exciting i'd say.

Similar Threads

  1. Replies: 0
    Last Post: 07-28-2005, 05:41 AM
  2. Replies: 0
    Last Post: 07-13-2005, 08:01 AM
  3. Replies: 0
    Last Post: 02-27-2005, 10:43 PM
  4. Replies: 0
    Last Post: 01-30-2005, 08:33 PM
  5. Replies: 8
    Last Post: 11-12-2004, 04:10 PM

Bookmarks

Posting Permissions

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