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

,CSV file import to website | HOW?

Reply to Message Icon

Original Message
Name: NooK
Date: October 23, 2007 at 14:38:14 Pacific
Subject: ,CSV file import to website | HOW?
OS: XP Pro
CPU/Ram: 1GB
Model/Manufacturer: 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?


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: October 24, 2007 at 22:48:34 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: NooK
Date: November 2, 2007 at 09:33:22 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 3
Name: Michael J (by mjdamato)
Date: November 3, 2007 at 11:39:32 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 4
Name: NooK
Date: November 5, 2007 at 05:56:46 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 5
Name: Michael J (by mjdamato)
Date: November 5, 2007 at 08:18:58 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal


Response Number 6
Name: NooK
Date: November 5, 2007 at 09:45:17 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 7
Name: Michael J (by mjdamato)
Date: November 5, 2007 at 10:06:10 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 8
Name: NooK
Date: November 5, 2007 at 11:46:17 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 9
Name: NooK
Date: November 5, 2007 at 11:48:34 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

echo "<table>";

^
MISSING SORRY


Report Offensive Follow Up For Removal

Response Number 10
Name: NooK
Date: November 5, 2007 at 12:12:02 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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?


Report Offensive Follow Up For Removal

Response Number 11
Name: NooK
Date: November 5, 2007 at 22:03:50 Pacific
Subject: ,CSV file import to website | HOW?
Reply: (edit)

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


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: ,CSV file import to website | HOW?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge