[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

testing a csv upload

Asked by sulentho in PHP Scripting Language

I have written the following script to upload the given csv into a table of the following structure

id | prod_id | att_cid | att_sid | att_count

The main issue is I need to provide the logic that will error out and print an error mssg is someone tries to upload 2 rows with the same combination of prod_id,att_cid and att_sid. Any help on this will be greatly appreciated. Thanks

Sulen

$uploaddir = "csv";
$allowed_ext = "csv,xls";
$max_size = "10000000";
$extension = pathinfo($_FILES['file']['name']);
$extension = $extension[extension];
$allowed_paths = explode(",", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}
if ($ok == "1") {
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
$filename=$_FILES['file']['name'];
chmod($uploaddir.'/'.$filename, 0755);
$handle = fopen ($uploaddir.'/'.$filename,"r");
$flag = 0;
while ($data = fgetcsv ($handle, 1000, ",")) {
$flag++;
if ($flag==1) continue;
if ($data[4]=='') {
$prodsql = "SELECT prod_id FROM products WHERE prod_sku='{$data[0]}'";
$prodresult = mysql_query($prodsql) or die("Invalid query: " . mysql_error().__LINE__.__FILE__);
$prodnum = mysql_num_rows($prodresult);
if ($prodnum == 0) { ?>
<table width="700" border="0" cellspacing="0" cellpadding="2">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="6" id="admin">
<tr>
<td width="6%" align="center"><img src="images/warning_icon.gif" width="35" height="35"></td>
<td width="94%" class="system_msg">The product SKU <? echo $data[0]; ?> is INVALID.</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<?
} else {
while ($prodrs = mysql_fetch_assoc($prodresult))      {
$acsql = "SELECT att_cid FROM attribute_categories WHERE att_cname='{$data[1]}'";
$acresult = mysql_query($acsql) or die("Invalid query: " . mysql_error().__LINE__.__FILE__);
while ($attcrs = mysql_fetch_assoc($acresult))      {
$assql = "SELECT att_sid FROM attribute_subcat WHERE att_sname='{$data[2]}'";
$asresult = mysql_query($assql) or die("Invalid query: " . mysql_error().__LINE__.__FILE__);
while ($attsrs = mysql_fetch_assoc($asresult))      {
$sql = "UPDATE prod_attributes SET att_count = att_count + $data[3] WHERE prod_id='".$prodrs['prod_id']."' AND att_cid='".$attcrs['att_cid']."' AND att_sid='".$attsrs['att_sid']."'";
$result = mysql_query($sql) or die("Invalid query: " . mysql_error().__LINE__.__FILE__);
}
}
}
}
}

 
Related Solutions
Keywords: testing a csv upload
 
Loading Advertisement...
 
[+][-]01/29/07 05:05 AM, ID: 18418668Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP Scripting Language
Sign Up Now!
Solution Provided By: pbonneau
Participating Experts: 1
Solution Grade: A
 
[+][-]05/15/07 12:23 PM, ID: 19095494Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]05/24/07 05:27 PM, ID: 19153819Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81