Insertion of product list form .txt or .xls

They have: 22 posts

Joined: Feb 2002

I would like to use PHP script to insert a crated product list from .txt or .xls file to main product page.

Example of what I mean is here : www.computershop.pisa.it

The table that I would like to have created, shuld not resize the page, the text should be similar to the site text.

How could I do this?
or.
is there some other alternative how to make this (but I don't know MySQL)?

Busy's picture

He has: 6,151 posts

Joined: May 2001

information drawen from a database would be easier, but you can do what you want to do I think with flat file.

productlist.inc

$item_1 = ("the details .....");
$item_2 = ("the details .....");
$item_3 = ("the details .....");
$item_4 = ("the details .....");
$item_5 = ("the details .....");
etc

then call this page from the page you want it on:
include ("productlist.inc");

then make your tables

<?php
echo("$item_1");
?>

<?php
echo("$item_2");
?>

...

This is a very basic example, but in the $item_1 description could be product number table tags product name table tags ... to make the layout the same.
If your going to a lot of these pages I would reccomend learning MySQL, would be so much easier and faster.

They have: 22 posts

Joined: Feb 2002

Can someone help me to do this with MySQL.

Please.

He has: 296 posts

Joined: May 2002

Okay, first you need a MySQL database. Make sure it's set up and running. When you're sure it's up and running you need to make a table, I'll call it `catalog`. In PHP the syntax for creating a table is:

<?php
CREATE TABLE
`catalog` (
`
id` TINYINT(6) NULL AUTO_INCREMENT PRIMARY KEY,
// This makes a column called `id` for your item ID number. It's set to increase automatically with each insertion.
`item` VARCHAR(255) NOT NULL,
// This makes a column for your item name. It's set for a max length of 255 characters.
`description` TEXT NOT NULL,
// This makes a column for your items description.
`price` VARCHAR(10) NOT NULL,
// This makes a colum for your items cost.
`rating` TINYINT(5) NOT NULL
// This makes a column for your items ratings. People can vote a value of 1-10 and it will contain the average.
);
?>

That's probably not the best way to make it. But it's how I would. To grab an item(s) from the database you would need something like this:

<?php
$connect
= mysql_connect('localhost','USERNAME','PASSWORD');
// Replace USERNAME and PASSWORD with their respective items.
$db_con = mysql_select_db('DBNAME',$connect);
// Replace DBNAME with the name of your database.

// The following line declares the query to be done.
$query = mysql_query(\"SELECT id,item,description,price,rating FROM `catalog`\");

// Next we need to use the query. The while() function keeps the results flowing.
while(
$result = mysql_fetch_assoc($query)) {
 
$id = $result[\"id\"];
 
$item = $result[\"item\"];
 
$description = $result[\"description\"];
 
$price = $result[\"price\"];
 
$rating = $result[\"rating\"];

  echo (\"ID:
$id<BR>\n\");
  echo (\"Item:
$item<BR>\n\");
  echo (\"Description:
$description<BR>\n\");
  echo (\"Price: \$
$price<BR>\n\");
  echo (\"Rating:
$rating<BR><BR>\n\n\");
}

exit(
$db_con);
?>

People more fluent in PHP/MySQL should be able to help you more, but I hope I helped some Smiling

[James Logsdon]

They have: 22 posts

Joined: Feb 2002

necrotic, thanks for helping me Wink

I have 2 questions :

1. Because I would like to use this database for a computer store,
I would like to display different categoryes of catalog. How can I display for example just monitors or CPU or Ram data?

2. How can I fill database with all product data?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

1. You would have to design your database to allow different categories. Probably by adding another table that holds these items along with what category they're in.

2. You would use an INSERT to put data into your database.

You might want to take a second to read up on mySQL so you really understand what you're doing, take a look at the docs at: mysql.com

PJ | Are we there yet?
pjboettcher.com

dk01's picture

He has: 516 posts

Joined: Mar 2002

About Peter's response to your first question.
You could have another column named 'catagory' with the catagory that each item is placed in and then do:
$catagory='monitors';
$query = mysql_query("SELECT * FROM `catalog` WHERE catagory='$catagory'");
instead of:
$query = mysql_query("SELECT id,item,description,price,rating FROM `catalog`");

-dk

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.