Computing.Net > Forums > Web Development > ,CSV file import to website | HOW?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

,CSV file import to website | HOW?

Reply to Message Icon

Name: NooK
Date: October 23, 2007 at 14:38:14 Pacific
OS: XP Pro
CPU/Ram: 1GB
Product: Asus
Comment:

I'm looking to import information from a .csv file that my wholesaler keeps in their ftp. What is the best way to pull this file and display it on my website. I dont want to display the whole thing just particular records. Can PHP do this?



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: October 24, 2007 at 22:48:34 Pacific
Reply:

Yes, any server-side language, including PHP can accomplish this. You state you only want to display part of it so you would need to provide details for what is included in the file and how it is to be parsed.

Michael J


0

Response Number 2
Name: NooK
Date: November 2, 2007 at 09:33:22 Pacific
Reply:

Right now im runnign WAMP Server on my system just while im trying to build my catalog. I managed to use a neat little tool called mySQL admin to build my database and table. All the data seems to be corretly inported. Now IM trying to do a simple search through the data base using PHP to pull up a record and display in my catalog "webpage"

I have this line of code right under the <html> tag ;

<?php
$connect = mysql_connect ("localhost", "root", "");
?>


Then to try and display, i used this code Pricelist being my database and table name,


<?php
mysql_select_db("pricelist");
$query = SELECT ProductTitle from pricelist WHERE SCPartNum = "NB-AS-F3SC-B1";
$results = mysql_query($query)
or die(mysql_error());
echo $results;
?>

Just errors out, obviously


As you can see im a rookie to all of this buy im willing to learn, so if anyone can direct myself the right way, that would be great.


0

Response Number 3
Name: Michael J (by mjdamato)
Date: November 3, 2007 at 11:39:32 Pacific
Reply:

Ok, this is a separate problem and should have been written as a new post. But anyway...I see a few problem.

1) You should add error handling to the other database commands to ensure there are no errors there:

$connect = mysql_connect ("localhost", "root", "") or die(mysql_error());
mysql_select_db("pricelist") or die(mysql_error());

And just to verify - You have a database named "pricelist" and a table within that database named "pricelist" as well? The database name and table names are two different things.

2) Your query looks OK except that you are not assigning it to the variable correctly. It is a string and should be enclosed in quotes. And, I'm not 100% sure but I have always seen values in queries used with the single quote mark, not the double.

So, try defining your query like this:

$query = "SELECT ProductTitle FROM pricelist WHERE SCPartNum = 'NB-AS-F3SC-B1' ";


3) Lastly once you run a query, what is returned back is a resource ID, not the actual results. So, your echo command will result in something like "Resource ID #15" - assuming the query completed successfully. You need to use the appropriate commands to read the data.

Replace your echo with this:

echo "<table>";
while ($record = mysql_fetch_assoc($results) {
echo "<tr>";
foreach ($record as $value) {
echo "<td>$value</td>"
}
echo "</tr>";
}
echo "</table>";

Michael J


0

Response Number 4
Name: NooK
Date: November 5, 2007 at 05:56:46 Pacific
Reply:

Hey Michael,

I put in the echo code, it got rid of the RESOURCE ID # popping up. Now I'm recieving an error;

Parse error: syntax error, unexpected '{' in C:\wamp\www\catalog.php on line 49

Notes: DB - scpricelist, Table - pricelist

<?php
mysql_select_db("scpricelist");
$query = "SELECT ProductTitle FROM pricelist WHERE PartNum = '90-PN513CE-00100' ";
$results = mysql_query($query)
or die(mysql_error());
echo "<table>";
while ($record = mysql_fetch_assoc($results) {
echo "<tr>";
foreach ($record as $value) {
echo "<td>$value</td>"
}
echo "</tr>";
}
echo "</table>";
?>

Dreamweaver is saying this code is line 49 from the above: echo "<tr>";

I checked online, can't seem to find the syntax to get this to work.

Your help is most appreciated.
Talk to you soon


0

Response Number 5
Name: Michael J (by mjdamato)
Date: November 5, 2007 at 08:18:58 Pacific
Reply:

I don't test my code before posting. I expect the recipient to be able to find minor typos.

You need to add a semicolon at the end of line 47.

Michael J


0

Related Posts

See More



Response Number 6
Name: NooK
Date: November 5, 2007 at 09:45:17 Pacific
Reply:

Thanks for all the help mike,

Any other ideas.... I added the semicolon at the end of line 47, it fixed the first error now I recieve this error:

Parse error: syntax error, unexpected T_FOREACH in C:\wamp\www\catalog.php on line 49

Heres the code layout,

<?php
mysql_select_db("scpricelist");
$query = "SELECT ProductTitle FROM pricelist WHERE PartNum = '90-PN513CE-00100' ";
$results = mysql_query($query)
or die(mysql_error());
while ($record = mysql_fetch_assoc($results)
foreach ($record as $value)
echo "<tr>"; <--------------LINE49
foreach ($record as $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
?>


I can't find anything online abou this error, one site was pointing at semicolons and stuff, but I think thats all fixed. Like I said before please bare with me, Still a rookie, just started.


0

Response Number 7
Name: Michael J (by mjdamato)
Date: November 5, 2007 at 10:06:10 Pacific
Reply:

I'm not trying to be rude, but do you really need me to point out the obvious for you? Do you not see that you modified the code from the last time you posted it?

Look at line 48 and line 50 - they are the same. You have apparently duplicated it. Remove line 48.

Michael J


0

Response Number 8
Name: NooK
Date: November 5, 2007 at 11:46:17 Pacific
Reply:

Mike be as Harsh or as Rude as you want, your helping me learn! That was my bad when copy and pasting and changing things, Ive been starting at this stuff forever now. I thought that was a part of the code, sorry again. But guess what! I fixed up the code and now other error that I don't understand.

ERROR
Parse error: syntax error, unexpected T_ECHO in C:\wamp\www\catalog.php on line 49

<?php
mysql_select_db("scpricelist");
$query = "SELECT ProductTitle FROM pricelist WHERE PartNum = '90-PN513CE-00100'";
$results = mysql_query($query)
or die(mysql_error());
while ($record = mysql_fetch_assoc($results)
echo "<tr>";
foreach ($record as $value) <--------LINE49
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
?>

Your help is most appreciated


0

Response Number 9
Name: NooK
Date: November 5, 2007 at 11:48:34 Pacific
Reply:

echo "<table>";

^
MISSING SORRY


0

Response Number 10
Name: NooK
Date: November 5, 2007 at 12:12:02 Pacific
Reply:

FINALLY NO ERRORS, BUT guess what?? The page loads and nothing is DISPLAYED, just a two line break where the ProductTitle should be.


<?php
mysql_select_db("scpricelist");
$query = "SELECT ProductTitle FROM pricelist WHERE PartNum = '90-PN513CE-00100'";
$results = mysql_query($query)
or die(mysql_error());
echo "<table>";
while ($record = mysql_fetch_assoc($results)){
echo "<tr>";
foreach ($record as $value)
{
echo "<td>$value</td>";
}
echo "</tr>";
}
echo "</table>";
?>

Is it the code or the Database?


0

Response Number 11
Name: NooK
Date: November 5, 2007 at 22:03:50 Pacific
Reply:

Everything is working great now...Thanks for all you help mike


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: ,CSV file import to website | HOW?

CSV file import to website www.computing.net/answers/webdevel/csv-file-import-to-website-/3962.html

load csv file into a javascript file www.computing.net/answers/webdevel/load-csv-file-into-a-javascript-file/4099.html

Uploading a file using php www.computing.net/answers/webdevel/uploading-a-file-using-php/2751.html