Forum Moderators: phranque

Message Too Old, No Replies

mysql

phpmyadmin

         

customdy

11:46 pm on Dec 11, 2003 (gmt 0)

10+ Year Member



Our website contain several hundred products, currently all pricing is hardcoded into the html.

Would like to create a simple database that contains 4 columns

PN MSRP Discount_Rate Sale_price

I took a look at mysql and phpmyadmin, I understand how to make the calls from the website to the database to return the appropriate value but struggling with the database side of things.

Can I create an .cvs or .txt or excel file and upload it to the mysql or what is the simplest way to create the database?

Thanks

Timotheos

12:07 am on Dec 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure.

First you'll have to create a table. Then create the fields.

Then go to the SQL tab and hopefully you'll see a link that says "Insert data from a textfile into table"

customdy

1:12 am on Dec 12, 2003 (gmt 0)

10+ Year Member



Thanks for the reply.

I created the database in mysql

I then created the table in phpmyadmin

It then brings me to create the fields...
are the fields the columns?

Once the fields are created then it will allow my
to upload a file. What types of files will is accept?

Thanks
Dave

slade7

1:24 am on Dec 12, 2003 (gmt 0)

10+ Year Member



the fields are the columns.

with phpmyadmin you can insert data from a text file on your hard drive. Don't use a tab delimited - use something else to delimit.

When making the fields you'll have to tell mysql what kind of data is going in what field/column. That's the column types (varchar, smallint, etc) You'll have to read up on that at the mysql site

If you have your data in excel, and the data itself doesn't have commas you can save the excel file as csv and tell phpmyadmin you are delimited with comma's on the upload. Just keep a copy of the excel file as .xls too.. cause it does weird things when you try to open that .csv file again in excel... you know - excel tries to format everything for you.

If anybody has better ideas on how to move data around, edit it and re-upload it than excel I'm all ears - cause I have 20,000 plus rows at a time to dump and mess with.

customdy

1:32 am on Dec 12, 2003 (gmt 0)

10+ Year Member



Thanks, I will give it a try.

customdy

1:50 am on Dec 12, 2003 (gmt 0)

10+ Year Member



okay, got all the data uploaded and can browse the table, everything looks good on the server side.

Can someone tell me how to write the html code for the website or give me an example?

The table looks like this:

partnumber msrp discount saleprice
abc 100 10 90

Would need to call the database and search for the pn and then return the salesprice?

Thanks for your help.

slade7

4:19 am on Dec 12, 2003 (gmt 0)

10+ Year Member



If your sale price is a product of the msrp * discount rate, there is no need to store it in the database - you can just grab it with a little math as below

Just edit this script for your particulars & stick it in any html doc inside the body tag. You HAVE to rename the file whatever.php instead of whatever.htm

This is about as simple as it gets... you can do a lot more w/ php... try to think like a lazy person who wants the computer to do all the work, and you will get along fine with php

<?php
$link = mysql_connect ("localhost", "user", "pass")
or exit ("could not connect to mysql");

mysql_select_db ("yourdbname")
or exit ("could not select db");

$result = mysql_query ("SELECT * FROM yourtablename
ORDER BY partnumber ASC");

echo "<TABLE BORDER>
<TR>
<TH>Part #</TH>
<TH>MSRP</TH>
<TH>Disc Rate</TH>
<TH>Sale Price</TH>
</TR>
";

while($row = mysql_fetch_array($result)) {
$pn= $row["partnumber"];
$msrp= $row["msrp"];
$disc= $row["discount"];
$salepr= round($msrp * $disc, 2);

echo "<TR>
<TD>$bull</TD>
<TD>$msrp</TD>
<TD>$disc</TD>
<TD>$salepr</TD>
</TR>
";
} //this closes the loop
</TABLE>
?>

customdy

6:34 pm on Dec 12, 2003 (gmt 0)

10+ Year Member



Thanks for the detailed reply, I will give it a try tonight.
Thanks